I have a variable in a repeat which sets to 1 when the item is selected and 0 when it it not.
This then goes to a form with the productID and the form gets submitted.
However when the form has gone through and I reopen the modal the divs that have been set to var=1 are still showing green.
Is there a way I reset ALL var=0 when the form is submitted in the repeat region?
I would use an array, outside of the repeat, that you add the id of the selected item to. You could clear it with one command, and show a selected icon/check when the array contains the id of the item you’re repeating
To identify each item in the repeat, you add the id of the item selected to the array and then look to see if it is present (I presume each line’s item has a unique id - such as autoID in yours)
i.e.
Add your array to the page (assume I’ve given mine an id of arr_selected)
You will use arr_selected.addUniq(autoID) to add an item
and arr_selected.remove(autoID) to remove it
You can then then use arr_selected.contains(autoID) in a dmx-show expression for a selected icon or for a dmx-class expression
If there’s a field to be sent via a form you could disable it using !arr_selected.contains(autoID) so it isn’t sent when the item isn’t selected
To empty it, just use arr_selected.empty() on form success or modal hide etc.
ok so that has got the green bg working, however I’cant get the white bg to work.
as soon as I add the !== then as soon as you press the second option the green bg goes white.
Your original expression said that it should be white if there was anything in the datastore that didn’t match the autoID (so any other autoID would satisfy it as true)
What you actually wanted was that the datastore didn’t contain a record with the autoID