Binding to an object in a list


I have a container that has a button and text. The container is set to repeat.
I created a list with three objects: the button name, the text to be shown, and the third is a true or false variable ‘showText’.
The default is for the buttons to be displayed but not the text. When the user presses any button, the text under the appropriate button should show. If they press the button again, the text should hide. And so on…
I wanted to bind the button to showText using ‘Set page variable’. However, I see that it is only possibly to bind the button to the list of the objects and not to showText specifically.
Would appreciate any advice on what to do.


There are multiple options on how to approach this. First, if you want to directly change the showText variable under each item, if you have a schema like this:

First, set the visibility of the text as current.showText. Then, set the button tap event to “Set page variable”, variable name as “mylist”, and assigned value into the following formula:
SET_ITEM(pageVars.mylist, repeatedInfo.current.index == index, SET_KEY(item, “showText”, !item.showText))

This first finds the correct item in the page variable using the current index, and then toggles the showText property of the corresponding item directly. In the case your app allows for users to add or remove items from the variable, the use of indices could break this visibility - in that case, consider having a unique ID for each of the items and using == to find the item instead.

In the case your data is coming from a data resource, i.e. it is a data variable and you want to use a page variable to indicate which of the texts is visible:

  1. Make sure all the data items have some sort of unique ID. Let’s assume this is in a field called “id”. Note that the items in the data don’t need to have the property “showText” in this case!
  2. Create a list of texts page variable called visibleTexts
  3. Bind the visibility of the text components to IS_IN_ARRAY(pageVars.visibleTexts,
  4. Bind the button tap event into an IF flow function with IS_IN_ARRAY(pageVars.visibleTexts, that checks if the item is in the list already
  5. If the repeated item is not in the list, the second (lower) output of IF is triggered. There, we use a set page variable with the formula WITH_ITEM(pageVars.visibleTexts, If said item is already in the list, the IF flow functions’ second output is triggered. There, we should use a set page variable with WITHOUT_ITEM(pageVars.visibleTexts, to remove the text visibility.

Hopefully this helps! Let me know if there are any issues.

1 Like

Fantastic! Thanks a lot!