Using setFieldValue with cascading dropdowns

Forums Cascading dropdowns Using setFieldValue with cascading dropdowns

Viewing 3 reply threads
  • Author
    Posts
    • #18728
      Ivan Wilson
      Participant

      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

    • #18748
      Alexander Bautz
      Keymaster

      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

    • #18835
      Ivan Wilson
      Participant

      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?

    • #18872
      Alexander Bautz
      Keymaster

      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

Viewing 3 reply threads
  • You must be logged in to reply to this topic.