Home › Forums › Cascading dropdowns › Using setFieldValue with cascading dropdowns
Tagged: setFieldValue spjs.casc.init
- This topic has 3 replies, 2 voices, and was last updated 7 years, 1 month ago by Alexander Bautz.
-
AuthorPosts
-
-
November 14, 2017 at 00:26 #18728
I’m having problems with trying to update fields after the cascading dropdowns have been initialized. I’m calling spjs.casc.init rather than using the cascading dropdown tab.
I’m using a people picker field to look up and set the appropriate values for the dropdown. This works great prior to calling the spjs.casc.init method. However, once the cascading dropdowns have been set up, using setFieldValue for the underlying fields does not update the dropdowns. I’ve also tried calling spjs.casc.init and spjs.casc.clear, but without much luck.
How can I update these fields/dropdowns after spjs.casc.init has run? Alternatively, is there a way to programmatically remove the cascading dropdowns so that I can set the fields and then cal spjs.casc.init again?
I’m using v4.4.3.24 of DFFS
-
November 14, 2017 at 22:25 #18748
Have you tried to enable “debug” to see that the value is actually set in the field?
If it is – is there a valid option in the dropdown with the same value as the value set in the textfield?
Alexander
-
November 21, 2017 at 21:04 #18835
It looks like it is a timing issue. If I call setFieldValue for each of the fields configured for cascading dropdowns, only the first call works. However, if I put a timeout of 100 ms between each call, then they work as expected.
My old code:
setFieldValue('WorkCountry',countryName); setFieldValue('State0',stateName); setFieldValue('WorkLocation',locationName);
New code:
setFieldValue("WorkCountry", countryName); setTimeout(function () { setFieldValue("State0", stateName); setTimeout(function () { setFieldValue("WorkLocation", locationName); }, 100); }, 100);
I’m guessing that the setFieldValue is getting invoked prior to the cascading dropdown logic. Is there a better way of updating the fields instead of using a timeout?
-
November 24, 2017 at 00:19 #18872
I did try to set the value of each of the cascading dropdowns in my test environment and it works without the timeout so I’m not sure where to begin, but do you have a lot of items in the dataset populating the casc?
Using a timeout will work unless it is related to the time it takes to download the dataset as the time could be more than 100ms sometimes.
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.