Defining variables based on Xano-linked checkboxes

I built a checkbox list based on a collection from Xano. Now I would like to create a variable with an array that lists the names of all the ticked checkboxes.

I was able to make this work with a different element through the currentSelection. However with my checkbox from Xano I am not given a currentSelection that I can use to define my variable.

Please watch this brief screen recording to explain my issue.

Check this answer out, it’s basically what you need but with form fields instead. Same logic tho.

You would basically do this on change/click and work with the event and build your own selected property. A little tricky, but doable)

1 Like

There is also this tutorial for keeping track of the selection, plus a workflow to select/deselect all the checkboxes :slight_smile:

1 Like

Thank you! With your tutorial I was able to build just what I wanted :slight_smile: Thank you so much

1 Like

Hi Mariano, I thought I could replicate your tutorial for the exact same use case, just with a different item from the same collection.

Here is a quick video to better explain my issue:

The only difference that I think could have not made this work is that all the specialisation names are unique, whereas the risk group numbers are duplicate at times with the same items in the collection having the same risk group. Nonetheless, they should still be correctly linked to each of my checkboxes.

You need to use unique ids for this to work, it can’t work with duplicated ids because you can’t know which one you need. Once you have a list of selected ids you can get all the other data from your collection.

Initially I thought your suggestion worked using unique ids. The performance initially was fine, but I only realised now that when I start clicking the checkboxes very quickly the array eventually becomes inaccurate. This is still not the case for my initial use case where the ids are much “more unique”

It is indeed a method that suffer from race conditions, but it’s the easiest and quickest implementation.
There are various methods to overcome that, like inserting every change in a queue where operate the same logic, or storing the data in a different way (an object like {id1:{checked: true}, id1:{checked: false}}).

I just made a wild set of selections but slowly in between clicks and found no errors. I heavily suspect this to be a performance on WeWeb, although then I still don’t understand why it’s not the case for longer id strings (or more unique as previously defined)

I can work around this with a time delay workflow, but this does not seem like a great solution?

Do you have a tutorial available the data in an object like you described? I am still very new to web development and low code

There is no more or less unique, ids are unique or are not unique, and you must have unique ids for this to work.

Makes sense, but then how come I am not having the race condition issues in my other array that is set up the exact same way. They are on top of each other in my workflow could this be part of the problem?

instead of an array store the checkob status in an object like {id1:true, id2:false} where the keys are the ids and the values are boolean for the checkbox status.

1 Like

Regarding my interim solution of using a time delay, I am only able to implement this within my “on change” workflow. But not on the actual ability to “change” the checkbox statues and trigger the whole workflow. Any ideas how to implement a time delay for my purpose?

a time delay will only create delayed race conditions.
Not sure why you have two updates because once you know the id of what is selected you can access the rest of the data.

I have two updates because I need to define multiple variables based on the selections. I need these variables for my logic further down the line.

But I suppose if I store my data in an object like you suggested I could derive the input I require for my logic from said object?