Quantcast
Viewing all articles
Browse latest Browse all 6517

New Post: SPServices.SPCascadeDropdowns

Hi.

I've been using SPServices.SPCascadeDropdowns successfully for a while now in various projects. Normally single parent-child and the odd parent-child-grandchild.

In this issue, I'm working with a pseudo parent-child-grandchild relationship in that the same child applies for all parent. If that makes any sense.

Another way of thinking about it is that there are essentially 2 parent tables.

So we have
  • Parent table = Directorate
  • Child table = Region (regions within a Directorate), only the Directorate is the same/identical for all regions.
  • GrandChild table =District. Region AND Directorate specific!!
The District is the clincher since by themselves, Region and District function fine as parent-child provided you specify the Directorate with a CAML query. This would be because the lists would be in a separate subsite, one for this Directorate and one for that Directorate. Using CAML in the SPServices.SPCascadeDropdowns works perfectly.

Now I have a list that has all three dropdowns. So I fashioned an if statement to determine which directorate was choosen and changed the CAML accordingly. Problem is, on Directorate drop down change, the District doesn't update properly, it stays with whichever Region was choosen. Likely I'm doing something wrong. (Ya think?). My js is below.

Any and all comments or ideas are welcome and appreciated.

P.S. I wouldnt be able to make my site as intuitive and functional as it is without SPServices. Thanks Marc.
<script type="text/javascript" src="/org/1275526/priv/jQuery/jquery.min.js"></script>
<script type="text/javascript" src="/org/1275526/priv/jQuery/jquery.SPServices.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

//alert($().SPServices.SPGetCurrentSite());   

$("select[title$='Directorate']").change(function () {
    
    var dir=$("select[title$='Directorate']").val();
        //alert(dir);             
    if (dir == "EED") {
        alert ("EED choosen");
        
        //set district to show only EED districts
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "{4E004980-5B45-4A52-9AAC-39875DEDCDC4}",
            relationshipListParentColumn: "Region",
            relationshipListChildColumn: "Title",
            parentColumn: "Region",
            childColumn: "District",
            CAMLQuery: "<Eq><FieldRef Name='Directorate'/><Value Type='Lookup'>EED</Value></Eq>",
            debug: true
        });
    } 

    else if (dir == "WED") {
        
        alert ("WED choosen");  
        //set district to show only WED districts       
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "{4E004980-5B45-4A52-9AAC-39875DEDCDC4}",
            relationshipListParentColumn: "Region",
            relationshipListChildColumn: "Title",
            parentColumn: "Region",
            childColumn: "District",
            CAMLQuery: "<Eq><FieldRef Name='Directorate'/><Value Type='Lookup'>WED</Value></Eq>",
            debug: true
        });         
    }

    else {
        //hide Region and district fields as they are not
            alert ("nothing? We'll do sonmething with this later");
    }
}); //end of function
}); //end of Ready
</script>
Carl

Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>