Home › Forums › Cascading dropdowns › Switching between lookupLists
- This topic has 7 replies, 2 voices, and was last updated 6 years, 8 months ago by Alexander Bautz.
-
AuthorPosts
-
-
April 24, 2018 at 14:38 #20639
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 6 years, 8 months ago by Zaruba.Ivan.
-
April 25, 2018 at 21:40 #20661
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
-
April 26, 2018 at 06:20 #20665
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
-
April 30, 2018 at 21:20 #20744
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 6 years, 8 months ago by Alexander Bautz. Reason: Fixed typo
-
May 1, 2018 at 07:34 #20760
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:
-
May 1, 2018 at 08:48 #20768
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
-
May 1, 2018 at 09:35 #20772
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
-
May 2, 2018 at 21:10 #20804
Thanks for the feedback – I’m glad it worked out.
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.