Hi all,
I simply want to create a list like this {“type”:“adult”},{“type”:“adult”},{“age”:1},{“age”:1} ..where input value for adult is 2, input value for infant is 2.. and this repeatation should change as per input values…Coul someone please give me a simple way to create this.
Regards,
BChoudhury
Hi! You can do this pretty simply, you just need to build the list with workflows instead of trying to manually format the JSON.
The easiest way:
Set a custom state on the page (like final_list) that holds a list of texts or objects.
When the user enters “Adults = 2,” just run a workflow that adds {“type”:“adult”} to that list twice.
Same idea for infants, if the input says 2, add {“age”:1} two times.
If you don’t want to manually repeat actions, you can also use a tiny recursive backend workflow that loops until the count reaches zero.
That’s pretty much it, dynamic list based on input. I hope this helps.
Many Thanks. I tried the same concept setting up the custom state on my index page, and setting its value as index page’s temp_list :plus item {“type”:“adult”} when input adult is >=1 and so on. but it doesn’t work & same for infants. it returns only for 1 adults and 1 infant, even if the input is 2,3,…for adults and infants
Ah okay, the reason it’s only giving you 1 adult and 1 infant is because :plus item only adds one entry each time. It doesn’t repeat based on the number you type in, so Bubble is doing exactly what you told it to do… just once.
The easier way to handle this is to generate the list in one go instead of trying to loop it yourself.
You can do that with Bubble’s :make list function:
- For adults:
{"type":"adult"} :make list Input Adult's value
- For infants:
{"age":1} :make list Input Infant's value
Each one automatically repeats the item as many times as the input value.
Then combine both lists:
Adults List :plus list Infants List
That should give you the correct counts every time without extra workflows.
Thanks for your response. But it seems :make list operator is not available. It’s truely shocking for a beginer like me to see it’s so hard to create a simple list. But, hope is alive as long as helping hands like yourself are there.
Thanks
1 Like
If it’s for having a list you can edit on the page (before sending to the databse) You could try this plugin: Bubble Plugins | Build and extend apps without writing code