This project has moved and is read-only. For the latest updates, please go here.

SPCascadeDropdowns on a non-SharePoint Page

Jun 24, 2013 at 10:21 PM
I've been looking for information on this to avoid having to dive in to the code of SPServices, so I figured I would ask here.

I'm currently using SPServices to build custom-coded pages and transmit information back and forth via the SharePoint web services. Thus, I'm not using SharePoint to create any kind of forms/controls/etc. So far, I've done several things with SPServices that have worked perfectly, but given the options for CascadeDropdowns not having anywhere for me to input the ID of the dropdown control, I'm guessing my use case isn't possible without modifying the code.

Anyone run across this before and solved it?

Jun 24, 2013 at 11:40 PM
[ Full disclaimer: I have not tested the code below]

It should be possible... but your HTML markup must have the proper properties set... SPCascadeDropdowns uses the display name of a column to find them on the page - basically, the values you define on the parentColumn and childColumn input parameters... These values are also found on a SP form input element, defined in the 'Title' attribute... so... if you set your <select> markup as:
<select name="Country" Title="Country Name">
    <option value="1">USA</option>
    <option value="2">CANADA</option>
    <option value="3">MEXICO</option>

<select name="state" Title="State Code">
And have a list named "States" with the following columns:
1 |NJ   |USA
2 |NY   |USA
then the following:
    relationshipList: "States",
    relationshipListParentColumn: "Country",
    relationshipListChildColumn: "Title",
    relationshipListSortColumn: "Title",
    parentColumn: "Country Name",
    childColumn: "State Code",
    listName: "Cities"
should work... Post back and let us know.

Jun 26, 2013 at 5:31 PM
Thanks for the suggestion Paul! I'm trying to adapt what's above to the code in my page, but it doesn't seem to be correctly triggering at all (and I'm not getting any errors because I'm not using SharePoint forms - at least that's my guess). I'll let you know when I figure it out.

I'd also always appreciate any further suggestions if people have them!
Jun 27, 2013 at 5:41 PM
If you turn debug on, you should get errors if the elements aren't found in the page. However, given that fact that you aren't operating in a list form, most bets are off. You may be better off simply implementing something yourself.

Jul 1, 2013 at 6:12 PM

Thanks for the reply - debug mode unfortunately doesn't show error boxes since I'm not working in the list form, as you guessed. As for the code, I actually got it to work as-is for use in non-SharePoint forms/pages by eliminating spaces and a hyphen from my list name. I'm sure that wasn't what the ultimate issue was, but I must have had something out of sync with my static vs. display names.

Anyway, I can confirm that this code DOES work outside of SharePoint list forms, as long as you have the correct items in the correct fields! :)

Also, I got it working with a filter control on the same page used for the first drop-down so if anyone has any questions about filter and cascade on the same page, I can confirm that works too.
Jul 3, 2013 at 2:07 PM
Awsome. This question seems to come up often here on the forums, so maybe this will be the post to use as 'go here for how to' :)

By the way: with debug: true, if you don't see any error boxes, then that's good. That means that the utilities was able to find all they it needed and it encountered no errors.


Sent from mobile device.
Jul 23, 2013 at 11:01 PM
OK so I've got a new one to add to this...I have three drop downs now and three corresponding lists. I use SPFilter to fill the first "Parent" drop down. I'm guessing this is usually done automatically as part of creating the form, but outside the SharePoint UI, I have to populate it myself.

I then have two cascade functions to populate the two other drop downs - DD2 and DD3.

Everything seems to populate correctly, but I'm getting a server 500 (internal error) saying a list isn't found when it goes to do a search. If I drill down a little further in the SOAP packet, I see it's requesting a list that's got a blank name...where in the query would that be triggered? Is there some second-level request in cascade that I'm just not seeing. At a high level, this is what it looks like:
            relationshipList : "Countries",
            relationshipListColumn : "Title",
            columnName : "Country",
            CAMLQuery: "<Eq><FieldRef Name='display'/><Value Type='Boolean'>1</Value></Eq>",
            completeFunc : null
        //Automatic cascading dropdowns driven by **U_CollegeBU & **U_BURole lists.
            relationshipList: "Regions",
            relationshipListParentColumn: "Country",
            relationshipListChildColumn: "Title",
            relationshipListSortColumn: "ID",
            parentColumn: "Country",
            childColumn: "Region",
            CAMLQuery: "<Eq><FieldRef Name='display' /><Value Type='Boolean'>1</Value></Eq>",
            relationshipList: "States",
            relationshipListParentColumn: "Region",
            relationshipListChildColumn: "Title",
            relationshipListSortColumn: "ID",
            parentColumn: "Region",
            childColumn: "State",
            CAMLQuery: "<Eq><FieldRef Name='display'/><Value Type='Boolean'>1</Value></Eq>",
BTW - I see you depricated promptText - I get that it's not necessary on forms anymore due to the errors, but it's extremely helpful when working outside the SharePoint UI, so I definitely see a need to continue using it!
Jul 23, 2013 at 11:03 PM
I should note with the above - everything works beautifully with the cascade. All the values are populating correctly. It's just irritating me that there's this random 500 error when it's searching for a blank list.