SPCascadeDropdowns not working within if statements

Feb 13, 2014 at 9:03 PM
Hi,

I'm using jQuery 1.11.0, SPServices 2013.02a and SharePoint 2010. I can get the SPCascadeDropdowns to work fine using the demo methods within the documentation so I'm happy with that. However I have three dropdown levels, with my third level being dependent on one of three lookup columns within the relationshipList. I've tried to achieve this by nesting the SPCascadeDropdown functions within if statements on the top level dropdown's change event. All dropdowns works fine but only for the first time after page load. When the top level dropdown is changed, the third level doesn't work. I know that the change event is being fired as I get the alerts.

Any help would be appreciated.
// First and second level dropdowns
$().SPServices.SPCascadeDropdowns({
    relationshipList: "Regions",
    relationshipListParentColumn: "Country",
    relationshipListChildColumn: "Title",
    parentColumn: "Country",
    childColumn: "Region"
});

// Third level dropdown
$( 'select[title="state"]' ).on( "change", function(){
    if ($(this).val() == "1") {
        //alert( $(this).val() );
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "States",
            relationshipListParentColumn: "Region_x0020_1",
            relationshipListChildColumn: "Title",
            CAMLQuery: "<Eq><FieldRef Name='Num'/><Value Type='Text'>4</Value></Eq>",
            parentColumn: "Region",
            childColumn: "State"
        });
    }
    if ($(this).val() == "2") {
        //alert( $(this).val() );
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "States",
            relationshipListParentColumn: "Region_x0020_2",
            relationshipListChildColumn: "Title",
            CAMLQuery: "<Eq><FieldRef Name='Num'/><Value Type='Text'>4</Value></Eq>",
            parentColumn: "Region",
            childColumn: "State"
        });   
    }
    if ($(this).val() == "3") {
        //alert( $(this).val() );
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "States",
            relationshipListParentColumn: "Region_x0020_3",
            relationshipListChildColumn: "Title",
            CAMLQuery: "<Eq><FieldRef Name='Num'/><Value Type='Text'>4</Value></Eq>",
            parentColumn: "Region",
            childColumn: "State"
        });   
    }
    
});
Feb 24, 2014 at 2:54 PM
I resolved this issue by using SPCascadeDropdowns for the first two dropdowns and then using SPFilterDropdown for the third dropdown. It works well.
Marked as answer by salw on 2/24/2014 at 6:55 AM
Coordinator
Feb 24, 2014 at 3:42 PM
Glad you solved it. The SPCascadeDropdowns logic is fixed to the field when it's first called, so the conditional logic you showed above wouldn't have worked.

M.