I’ve gone blank with this one but am sure it’s easy.
I have a dynamic table with one column containing a checkbox. I want to be able to tick any number of them but instead of passing them to a server action, I want to store the IDs in an array in local storage so I can then do other things with them.
I’ve put it all in a form but I’m not sure that’s necessary.
Well you can setup a localstorage manager and add a variable in it which will store the items.
Then with a checkbox group component, use the on:updated event and store its value there:
Yes, but happy to use the checkbox group component if that’s how I should do it. I think where I’m confused is the repeat part as the checkbox group component seems to need to have its own repeat.
Quite a lot of activity here One reply is just enough @sitestreet, we do our best to reply the questions here even during the weekends, when the office is closed.
If you are using checkboxes in a table and not with a checkbox group component then you can use the array component.
On click store the selected items in the array component
Add new dynamic event to the checkbox, on changed and check if the item is already in the array, if it’s there remove it and if it’s not - add it: arr1.items.contains(value) ? arr1.remove(value) : arr1.addUniq(value)
Use the dynamic events of the array component - on updated and and set its value to the local storage.
Thanks @Teodor. Sorry for all the posts, I have literally spent hours trying to get this sorted and kept seeing my post drop down the thread. Shall I remove them?
I’ll go through what you’ve suggested now but it’s looking very promising.
I appreciate all the time you spend in the forum and the speed you reply, even during the weekends.
Brilliant @Teodor. I’ve not used the Array Component before and that was the key. I’m sure to use it much more now I know about it.
I do, however, have one thing not quite right. It’s working perfectly except 80% of the time, the first checkbox I click doesn’t store the value. Further clicks work fine but the first one becomes out of sync - checked is NOT in the array, unchecked IS in the array but only that one checkbox. All the others work fine.
Hmm, it’s a strange one. I shall do some more testing. I’ve had the breakthrough I needed and am extremely grateful for that. I should be able to sort this issue.
This has been improved in Wappler 5.2.1. Now there are two new dynamic events for the checkboxes - checked and unchecked, so you can run different actions depending on the checkbox status.