SPCascadeDropdowns ... intermittent issue

May 14, 2015 at 4:50 PM
Hi there,

Just stumbled across your library, and it looks great! However, I've run into the following issue, maybe someone can help me figure it out ...

I have a SP 2007 site I'm trying to integrate the code with. I'm a site admin, so I use a CEWP to add the code to the page. Here's the code I use:
<script src="http://mossext/sites/ntl/LandD/assets/js/jquery-1.11.2.min.js"></script>
<script src="http://mossext/sites/ntl/LandD/assets/js/sputility.min.js"></script>
<script src="http://mossext/sites/ntl/LandD/assets/js/jquery.SPServices-2014.02.min.js"></script>
<script>
var urlParams;
(window.onpopstate = function () {
    var match,
        pl     = /\+/g,  // Regex for replacing addition symbol with a space
        search = /([^&=]+)=?([^&]*)/g,
        decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
        query  = window.location.search.substring(1);

    urlParams = {};
    while (match = search.exec(query))
       urlParams[decode(match[1])] = decode(match[2]);
})();

// wait for the window to load
$(window).load(function () {
  try {
    var urlValue = urlParams['CourseName'];
    SPUtility.GetSPField('WORKSHOP REGISTRATION for:').SetValue(urlValue).MakeReadOnly();
  } catch (ex) {
    alert(ex.toString());
  }
});

    $(document).ready(function() {
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "Ontario_Dates",
            relationshipListParentColumn: "Course",
            relationshipListChildColumn: "Title",
            parentColumn: "WORKSHOP REGISTRATION for:",
            childColumn: "Choose the DATE:"
        });
    });
</script>
The first block of code pulls a variable from the URL and sets the first dropdown (COURSE) with it (it also makes it ready only). The next dropdown (DATE) is list of available dates (just as a list of text, not a date format), which should change based on the COURSE item selected. When I load up the form, the COURSE is selected automatically (as expected), but there is nothing populated in the DATE list. Here's where it gets kind of weird ...

If I edit the page (by using the Site Actions > Edit Page option), and the exit edit mode, the DATE dropdown is magically populated with the correct data. That's the only time it works - just coming into the form from a link causes the DATE dropdown to be empty.

Any ideas would be helpful, thanks in advance!

Cheers,
Shawn
May 14, 2015 at 8:45 PM
I seem to have found a fix - instead of using:
$(document).ready(function() {
to start the block to cascade the lookup, I changed it to:
$(window).load(function() {
and it worked fine.
Marked as answer by winntshawn on 5/14/2015 at 12:45 PM