Multiselect not syncing fast for accurate use in javascript

i have a multiselect...when i try to use the values from it in javascript...it is never up to date on first try. like i have to try to access it twice so i can get the updated values. all other components sync fast for js use. is there a way to clear cache on multiselect component for immediate use in js?

You can yourmultiselectcomponent.setData('') before repopulating it again....
But can you share some screenshots



my multi select screenshots. happens even when remove all event handlers. happens even when i create a new multiselect.

tried setValue('') because setdata() does not seem to exist. Doesn't work. i think it's a caching issue. would be nice to release the cache.

setValue() works asynchronously under the hood. Can you share more about what you're trying to do?

In general synchronously writing-then-reading a widget property won't work as expected in Retool, since properties update asynchronously (otherwise you'd see the UI lock up every time there was a meaningful update).

yea. so i have a multi select in a form and on submit...it only submits whatever was previously selected in the multi select and doesnt submit what is actually in it. then when i try to see what value it has in javascript...it is also not updated.

Can you share more about how your app is set up? How are you setting the value of multiselect1 and how is your submit handler configured?

only setting value to multiselect1 via the component by picking the items in the component..but first via default values set. on submit it enters other values in the form into db. on success it does other things that are related to the multi select. On selecting an invoice from a list (select33.selectedItem._id): 1/ it stores via js "store_products_selected_for_invoice" the selected items in the multi select into a temporary state variable "json_products_selected_for_invoice". 2/clears previous invoice items in, 3/then adds those new selected items back to the invoice 3/ reload invoice. The issue is happening in 1/ where i try to get the value from the multiselect and store it.



Okay I found a solution for this here: "Keep variable references inside the query in sync with your app" query option questions

The issue was...i was using a temp state variable to store the multiselect values and it seems that you can't do that reliably without first having a few things in place...which can be found in the linked post. Mind blown that this isn't in the docs though...especially the part about enabling the advanced feature and how unorderly success handlers are when handling multiple executions.

2 Likes