# Defining variables based on Xano-linked checkboxes

**URL:** <https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198>\
**Category:** How do I?\
**Created:** [September 4, 2023, 3:14pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198 "2023-09-04T15:14:31Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 4, 2023, 3:14pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/1 "2023-09-04T15:14:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [September 4, 2023, 6:36pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/2 "2023-09-04T18:36:22Z")

</div>

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

> [@Are form variables not visible while the form is in a collection item?](https://community.weweb.io/t/are-form-variables-not-visible-while-the-form-is-in-a-collection-item/1138/6):
>
> No need to retrieve the input with js. You can keep track of the values using variables and workflows. create a variable of type object on your inputs add a workflow triggered on change where you change the variable Now on submit you can access the values: [chrome\_kiGf8an4uI]

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

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [September 4, 2023, 8:23pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/3 "2023-09-04T20:23:54Z")

</div>

There is also [this tutorial](https://community.weweb.io/t/checkboxes-within-a-collection-list/1379/3) for keeping track of the selection, plus a workflow to select/deselect all the checkboxes 🙂

---

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 7, 2023, 3:01pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/4 "2023-09-07T15:01:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 8, 2023, 6:57am UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/5 "2023-09-08T06:57:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [September 8, 2023, 8:34am UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/6 "2023-09-08T08:34:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 13, 2023, 8:36pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/7 "2023-09-13T20:36:38Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [September 13, 2023, 8:55pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/8 "2023-09-13T20:55:52Z")

</div>

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}}`).

---

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 13, 2023, 9:03pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/9 "2023-09-13T21:03:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 13, 2023, 9:05pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/10 "2023-09-13T21:05:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [September 13, 2023, 9:08pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/11 "2023-09-13T21:08:36Z")

</div>

> [@paulgassner](#):
>
> more unique

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

---

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 13, 2023, 9:11pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/12 "2023-09-13T21:11:17Z")

</div>

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?

 ![Screenshot 2023-09-13 at 23.10.01](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/8/805d6a6ab77a577f8522acc19be83cdff4f49fa3.png)

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [September 13, 2023, 9:14pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/13 "2023-09-13T21:14:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 13, 2023, 9:14pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/14 "2023-09-13T21:14:54Z")

</div>

> [@paulgassner](#):
>
> I can work around this with a time delay workflow

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?

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [September 13, 2023, 9:17pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/15 "2023-09-13T21:17:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulgassner](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@paulgassner](https://community.weweb.io/u/paulgassner)\
**Post date:** [September 13, 2023, 9:22pm UTC](https://community.weweb.io/t/defining-variables-based-on-xano-linked-checkboxes/4198/16 "2023-09-13T21:22:57Z")

</div>

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?
