Resetting Variables in repeat

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

If it was outside the repeat then how would it identify to one or more items in the repeat?

Code I am trying at the moment is:

<div class="row" is="dmx-masonry" id="masonry1" dmx-bind:repeat="view_all_products.data.query" columns="8">
                <div class="mouse col text-body mt-1 mb-1 pt-2 pb-2 ps-2 pe-2" dmx-on:click="ds_selected_prodID.insert({productID: autoID});var_selected.setValue(1)" dmx-on:dblclick="ds_selected_prodID.delete({$id: autoID, productID: autoID})" dmx-class:bg-success="ds_selected_prodID.data.where(`productID`, autoID, '===')" dmx-class:bg-white="ds_selected_prodID.data.where(`productID`, autoID, '!==')">
                    <p dmx-text="autoID">AutoID</p>
                    <p dmx-text="description" class="text-secondary">Product Desciption</p>
                    <img dmx-bind:src="image" class="img-fluid">
                </div>

How ever this does not seem to work either.
Can ANYONE help to see where I am going wrong…please.

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.

In your code you could use the .hasItems() formatter to return true/false after.where

e.g.

ds_selected_prodID.data.where(`productID`, autoID, '===').hasItems()

or

ds_selected_prodID.data.where(`productID`, autoID, '!==').hasItems()

I think .where returns a value (even if it’s an empty array) and an empty array on the client-side is evaluated as true

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.

Ah. The white one can be the same as the green. Just put a ! at the start

!ds_selected_prodID.data.where(productID, autoID, '===').hasItems()

thanks @bpj
But could you please explain what the ! at the beginning does, so I understand what has just gone please.

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