How to clear 'checked' checkboxes in a repeat?

Hey all

I have a number of repeats that have checkboxes, so user can save a number of items, or even all. This all works great.

However, if someone selects say item 1, 4, 5 from the repeat list and then does another search item 1, 4 and 5 remain checked even though they are different results.

What I’m trying to do is on form submit, or even on some server actions is clear all checkboxes. Whatever I try doesn’t seem to clear them. I’ve tried setting the value of the checkbox in the repeat to 0, even ‘1’ just to see if it’s working. I’ve trued true/false. I’ve tried a few other scenarios, too but they slip my mind right now.

Wondering if anyone might have an idea how I can do this?

You should set a key on your repeater. For performance the DOM only updates changes, the problem with checkboxes is that when the user changes the checked state it is an internal state, it doesn’t change the checked attribute on the element. That is why it doesn’t change. By setting a key on the repeater it will check the key for the repeated item and rerender the whole item including the checkbox.

Hey @patrick - thank you for the guidance here.

Would you be able to quickly show me how to correctly (best practice) apply a key on the repeater?

Is it here in repeat properties?
Screen Shot 2020-11-10 at 9.41.53 am

And if it is, what would be the most performant ‘key’ to set with the data binder?

Also, it mentions a warning, only use if needed as it will slow the repeater down - do you have any feedback on this?

Yes, the unique key. Set it to a unique value of your repeating item, normally the primary key (id) when you are repeating a recordset.

2 Likes

perfect, this worked. Thank you!