SPSService - Cascading Drop Downs

Sep 7 at 4:14 PM
Hi Everyone,

I am using a script to achieve a cascading drop down within SharePoint form.
The cascading drop downs work fine, until I make the drop downs 'mandatory' (required fields).

Ideally I want the drop downs to be mandatory. If I make the columns mandatory in the column setting in SharePoint, I get a script error when loading the form.
————————
Error in function
SPSService. SPCascadeDropDowns
Paramerter
parentColumn: City
Message
Column not found on Page

Click to continue
————————
(THE MESSAGE APPEARS IN A BLACK BOX)

I have really, been struggling with this for weeks!! literally, I will appreciate anyone to help me PLEASE!!!
All I need is the user to be informed that the drop downs are mandatory and cannot proceed/submit unless values are selected with the drop downs.

The code have within the SharePoint form is:

<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js" type="text/javascript"></script><script src="/esr/SiteAssets/jquery.SPServices-0.5.4.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">
    $(document).ready(function() {

        $().SPServices.SPCascadeDropdowns({

            relationshipList: "Districts",

            relationshipListParentColumn: "City",

            relationshipListChildColumn: "Title",

            relationshipListSortColumn: "ID",

            parentColumn: "City",

            childColumn: "District",

            promptText: "Select Pay Scale...",

            debug: true

        });



        $().SPServices.SPCascadeDropdowns({

            relationshipList: "Ward",

            relationshipListParentColumn: "District",

            relationshipListChildColumn: "Title",

            relationshipListSortColumn: "ID",

            parentColumn: "District",

            childColumn: "Ward",

            promptText: "Select Salary...",

            debug: true

        });

    });</script><script src="/tg_esr/Lists/Addresses" type="text/javascript"></script><script type="text/javascript"></script><script language="javascript" type="text/javascript">


    $(document).ready(function() {

        $().SPServices.SPCascadeDropdowns({

            relationshipList: "Districts",

            relationshipListParentColumn: "City",

            relationshipListChildColumn: "Title",

            relationshipListSortColumn: "ID",

            parentColumn: "City",

            childColumn: "District",

            promptText: "Select Pay Scale...",

            debug: true

        });



        $().SPServices.SPCascadeDropdowns({

            relationshipList: "Ward",

            relationshipListParentColumn: "District",

            relationshipListChildColumn: "Title",

            relationshipListSortColumn: "ID",

            parentColumn: "District",

            childColumn: "Ward",

            promptText: "Select Pay...",

            debug: true

        });

    });</script>]]></Content>
Sep 7 at 10:31 PM
Hi there, I had the same problem some months ago and found after a lot of digging that Microsoft changes the name of required fields on the form. If you view the page source you'll find that "Required Field" has been tacked onto the titles of your required fields. To fix this you just need to update your call to SPCascadeDropdowns to reflect the actual title on the page. In your case if City is a required field then you'll want to use "City Required Field" for the parentColumn.

Hope that helps.

Derek Nishino
Sep 13 at 3:48 PM
Thank you for replying to my post about the cascading drop downs. I really do appreciate it, as i have been struggling for months.

You mentioned how i need to change the 'title' of the parent Column to 'city' in the snippet i have 'SPCascadeDropdowns'

I have tried various things, ie changing title to city etc.. but it still does not seem to work.

I am not code savvy person, i really am not, i was wondering if you can give me a step by step approach to what exactly i need to do, in which areas, in the code of the page generated by Sharepoint via Sharepoint Designer? or Snippet 'SPCascadeDropdowns' on the page via Designer or need to change there properties of the Column in Sharepoint itself via the browser where you find the 'require field' option.

I really would appreciate if you can assist on this one... its been a long journey with no avail.

Please do let me know if you can help me.

PS. the parentColumns and childColumns that are required fields are:

City
District
Ward
Sep 16 at 6:12 PM
Hi Moses, for each required field in your $().SPServices.SPCascadeDropdowns calls you will need to modify the parentColumn and childColumn fields by appending "Required Field" to the values you already have. Here is what I think the calls to that function should be:
$(document).ready(function() {

        $().SPServices.SPCascadeDropdowns({

            relationshipList: "Districts",

            relationshipListParentColumn: "City",

            relationshipListChildColumn: "Title",

            relationshipListSortColumn: "ID",

            parentColumn: "City Required Field",

            childColumn: "District Required Field",

            promptText: "Select Pay Scale...",

            debug: true

        });



        $().SPServices.SPCascadeDropdowns({

            relationshipList: "Ward",

            relationshipListParentColumn: "District",

            relationshipListChildColumn: "Title",

            relationshipListSortColumn: "ID",

            parentColumn: "District Required Field",

            childColumn: "Ward Required Field",

            promptText: "Select Pay...",

            debug: true

        });
Everything else in your code should be the same. I hope this helps!

Derek Nishino
Sep 16 at 6:19 PM
One more comment that it looks like you are calling SPServices.SPCascadeDropdowns twice as many times as you should. You should only have the two calls that I gave you above in your code. Also, it looks like you might be using a really old version of SPServices. It looks like you are using 0.5.4 but the current version is 2014.2.

Derek Nishino
Sep 20 at 2:10 PM
This has worked wonder and untangled the problem I have had! I am pretty impressed with what you have done!!!! So that you very much Derek!!!!

However (and unfortunately) it has left me with another problem..

Now, if I leave one fields not filled out... i.e. City, District, Ward, or any of the other fields.. for example I have other fields that are mandatory on the form such as ‘Job Title’, etc.
If any mandatory fields are left incomplete. It throws an error back, usually in SharePoint, the same form will appear on the page with a caption in red asking one to complete the field. (now it doesn’t)
What do you suggest I do from here?
The error I get when a mandatory fields is not completed is…
Error
An unexpected error has occurred.
Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: 226f8d59-a288-4d38-91be-f6b05ce405df
Date and Time: 20/09/2016 14:01:43

Do you have a fix for this Derek?


Kindest Regards and thank you for the help so far! something that has been mind boggling for months!!!!
Sep 22 at 6:42 PM
Hi Moses, I'm not sure what might be causing the error you are seeing. You might try using some jQuery or JavaScript to disable the save button if those three mandatory fields are not completed.

In regard to your email message to me about the cascading not working with the newest version of SPServices try chaning the parentColumn and childColumn values back to their original. I think a fix was implemented in the newest version that works for some people that doesn't require you to add "Required Field" to those values. If all else fails you can just keep on using the old version...
  • Derek