Switching between lookupLists

Forums Cascading dropdowns Switching between lookupLists

This topic contains 7 replies, has 2 voices, and was last updated by  Alexander Bautz 4 months, 3 weeks ago.

  • Author
    Posts
  • #20639

    Zaruba.Ivan
    Participant

    Hi,
    is it possible to rebuild cascading dropdown by javascript? I have two lookupLists and when I am trying to switch them by redefining spjs.casc.init, the second one works properly only for the first field. When I switch it back to the first lookupList, all fields work properly again. Do I need to destroy or kill previous dropdown before redefining?

    Thank You,

    Ivan

    • This topic was modified 5 months ago by  Zaruba.Ivan.
  • #20661

    Alexander Bautz
    Keymaster

    Hi,
    Unfortunately there is no bult in “kill” function that completely removes the bindings on the fields to re-initiate casc with another datasoruce. This is possible to add, but if you switch the datasource you would need to keep the same functionality in EditForm to ensure it behaves the same there.

    Let me know if you have any more details and I’ll try to write up a function to properly “kill” the casc when it is re-initiated.

    Alexander

  • #20665

    Zaruba.Ivan
    Participant

    Hi,
    Thank You for reply. I have two rules and if I change field value, it switch between function CCDD_One or CCDD_Two. There is different amount of fields in functions.

    
    
    CCDD_One(); //Default Init CCDD_One
    
    function CCDD_One(){
        spjs.casc.init(
             {
             "manualMode":true,
             "dataSource":"",
             "lookupList":"listName_List1",
             "lookupListBaseUrl":"/sites/prj/pmo",
             "lookupListFields":["field1_List1","field2_List1","field3_List1"],
             "thisListFields":["field1","field2","field3"],
             "dropDownDefaultvalue":"",
             "filter":"",
             "hideEmptyDropdowns":false,
             "autoselectSingleOption":true,
             "clearInvalidSelection":false,
             "addOwnValue":false,
             "addOwnValueMouseover":"",
             "cancelOwnValueMouseover":"",
             "sideBySide":true,
             "debug":false,
             }
        );
    }
    
    function CCDD_Two(){
        spjs.casc.init(
             {
             "manualMode":true,
             "dataSource":"",
             "lookupList":"listName_List2",
             "lookupListBaseUrl":"/sites/prj/pmo",
             "lookupListFields":["field1_List2","field2_List2","field3_List2","field4_List2","field5_List2"],
             "thisListFields":["field1","field2","field3","field4","field5"],
             "dropDownDefaultvalue":"",
             "filter":"",
             "hideEmptyDropdowns":false,
             "autoselectSingleOption":true,
             "clearInvalidSelection":false,
             "addOwnValue":false,
             "addOwnValueMouseover":"",
             "cancelOwnValueMouseover":"",
             "sideBySide":true,
             "debug":false,
             }
        );
    }

    Thank You

    Ivan

  • #20744

    Alexander Bautz
    Keymaster

    I have added a “kill” function and will include it in the next release. You can try adding this snippet to your Custom JS:

    spjs.casc.kill = function(fin){
        jQuery.each(spjs.casc.data[fin].thisListFields,function(i,f){
            jQspjs("#dffs_" + f).find("input, textarea").show().val("");
            jQspjs("#" + f + "_casc").remove();
            jQuery("#casc_multiselect_table_" + fin).remove();
            jQspjs("." + f + "_casc_destroy").remove();
            jQspjs("#dffs_" + f + ".spjs_casc_notvalid").attr("title","").removeClass("spjs_casc_notvalid");
        });
        delete spjs.casc.dataObj[spjs.casc.data[fin].lookupList];
        delete spjs.casc.multi[fin];
        delete spjs.casc.data[fin];
    }

    and call it like this before you call “init” for the new config.

    spjs.casc.kill("Field_name_of_first_thisListFields_column");

    Let me know how this works out.

    Alexander

    • This reply was modified 4 months, 3 weeks ago by  Alexander Bautz. Reason: Fixed typo
  • #20760

    Zaruba.Ivan
    Participant

    Hi,
    thank You for reply. If I switch from Source A to Source B, It works properly. if I switch from Source B to Source A, there is error: “TypeError: Cannot read property “thisListFields” of undefined”. After pressing OK, cascade is rebuilt. I have two different “Filed_name_of_first_thisListFields_column”.

    Thank You

    Ivan

    Attachments:
  • #20768

    Alexander Bautz
    Keymaster

    Did you try to “kill” both versions of the casc each time? I didn’t handle “undefined” in the snippet – try it like this:

    spjs.casc.kill = function(fin){
        if(spjs.casc.data[fin] !== undefined){
            jQuery.each(spjs.casc.data[fin].thisListFields,function(i,f){
                jQspjs("#dffs_" + f).find("input, textarea").show().val("");
                jQspjs("#" + f + "_casc").remove();
                jQuery("#casc_multiselect_table_" + fin).remove();
                jQspjs("." + f + "_casc_destroy").remove();
                jQspjs("#dffs_" + f + ".spjs_casc_notvalid").attr("title","").removeClass("spjs_casc_notvalid");
            });
            delete spjs.casc.dataObj[spjs.casc.data[fin].lookupList];
            delete spjs.casc.multi[fin];
            delete spjs.casc.data[fin];
        }
    }
    

    Alexander

  • #20772

    Zaruba.Ivan
    Participant

    No, I just “killed” previous version. Maybe It is not absoutely clear, but handling “undefined” in the snippet solved problem. Thank You very much.

    Ivan

  • #20804

    Alexander Bautz
    Keymaster

    Thanks for the feedback – I’m glad it worked out.

    Alexander

You must be logged in to reply to this topic.