The listOfButtons will be used to store all of the button components in your app.
Add buttons to your list
There are a couple of ways you might do this. The first is to add each button when the screen opens. This approach will only work if your UI contains all the buttons you already need.
If however, you are creating your buttons dynamically, you can add each new button, one at a time, to the end of your listOfButtons with something like this:
Which button was clicked?
In this scenario, we’re going to create a function that accepts one input and returns one output. In the example below:
The function is called findPositionInList
The input is called clickedButton
The output is a new variable we have created called positionInList
The function goes through the listOfButtons one at a time, to see if it corresponds to the clickedButton. If it does the value of positionInList is returned, but if it doesn’t match then the positionInList is increased by one and the checking happens again.
Calling the function
Finally, when any button is clicked, you can tell which which button was clicked by calling the findPositionInList block like so:
Is there any way to set buttons to as such unlimited, as in, the list will just add the corresponding number to the end of the button, then find this item number in list.
I understand that you can create simply unlimited of everything, but I don’t get how to define for i in number of buttons. Is there a way to add to list, by means of clicking a show more button at the bottom of the screen?
Also to add to what I mentioned. I plan on using the duplicate feature, as I can create a widget (column) and this widget will contain loads of nicely displayed info like a photo, text, and then a button which is absolutely positioned over the top, so its one giant button in a way. How can I duplicate this, then set each piece of data in it to its corresponding list, and then get the button ID to retrieve the correct data from the list (the list contains a lot of data)
(edit)
As of now, I think the next page feature is the best option, and just do simple math, so for length of list = i, only allow to turn i divided by number of widgets per page pages.
I’m pretty sure MaxB meant by using the “in list () find the first occurrence of item ()” , which basically implies to avoid re-inventing the wheel.
Thanks @maxb (and @Mark!) who pointed out a few ways this can be dramatically improved. The 40+ blocks in my example above can actually be replaced with these 9 blocks:
And the really cool thing about this is that it never needs to be updated. In the first example, every time you add a new button to the designer you then have to add another button to your list. With the all ... in ... block your blocks will always be in sync with your design!
Thanks to you @domhnallohanlon, this is a new way for me to see it, so, is the “all button in” treated as a list?
Does this app work (just maybe remember that lists are bugged atm and use the workaround that I posted somewhere if the resulting position is not the desired one)?
FYI, the fix for the issue where the list index is sometimes off by one will be in the latest release that we expect to be deployed by the end of the day today.
I found it: Blocks tab > Any Componant drawer > the last block in the drawer is a single componant that can be changed once it is dropped in the composing area.