03.11.2010 Updated the code to eliminate the need to refer other external resources than jQuery. Removed the argument “lookupSourceListURL” from the function call.
The code is tested in IE, Chrome and Firefox. Opera is not supported.
NOTE: When updating existing script you must modify the function call and remove the argument “lookupSourceListURL”.
I have previously posted a solution for creating cascading dropdowns from SharePoint single line text fields. Populated based on a query against another list.
I have reviewed the script to add a few enhancements.
- No more need to create a calculated column in the “lookup list”
- Less arguments to pass to the function – sleeker code
- Overcomes a possible bug regarding the previous version using “BeginsWith” rather than “Eq” to match the items
This release (as the previous) has these features:
- “Converts” standard SharePoint single line text fields to dropdowns
- Uses the converted SharePoint single line text fields to hold the values
- Populates the dropdowns by querying any SharePoint list or library
- Dynamically fills or clears the hidden fields holding the selected value to adapt to changes in the selections – thus preventing “impossible combinations”
- Preserves selections during page refresh due to form validation
- Reads back and fills the dropdowns if used in EditForm
As always we start like this:
The jQuery-library is found here. The sourcecode refers to jquery-1.4.2.min. Some of the functions are not supported in previous releases.
The sourcecode for the file “spjs_CascadingDropDowns_v2.js” can be found below.
You can pull any values from another list – an example provided below.
The CEWP code – place below the Form:
- providerArr: Array of FieldInternalNames of the fields in the source-list
- consumerArr: Array of FieldInternalNames of the fields in the list where the dropdowns will be created
- lookupSourceListGuid: GUID of the source-list
- dropDownDefaultvalue: The default value of dropdowns that are not empty – ex. <select>
- numberOfDropdowns: Number of levels of cascading dropdowns – (2-5)
- debug: true or false – if true: the textfield that holds the dropdownvalue is visible and some alerts are displayed
Ask if anything is unclear.