I have a listView that data is pulling from query1. Inside the listView, I have a collapsible container and inside of that I have a currencyInput inside another container. I have an event that stores the currencyInputs when a change is made into a variable as an array but it only grabs the data from the first collapsible container. How can I do that for every currencyInput inside each collapsible container in the list view so I can take all that data and store it in my Retool DB?
In the screenshot below, I want to store all the currencyInputs as an array in a variable so the variable would look like this:
["1", "2", "4", "5"]
Is that possible?
One addition is that sometimes there could be more than just 2 collapsible containers.... so there could be Store A, Store B, Store C, Store D... etc.
Not sure how complex the app or your willingness to learn the code side of things is, but if the idea is to store this array on the same row as your store data, consider building a bids table with a foreign key instead. Working with arrays in a relational database is difficult and inefficient.
Thanks for the quick reply! So let's say in the listView, in each container I have currencyInput1 and currencyInput2.. I would put that code in each currencyInput event change but how would I put that exactly?
I reset the state but I got the error as shown. Do I add that code to the event change for each currencyInput's or to the container or list view itself?
The number of initial collapsible containers (store A, Store B, .. etc) in the listview depends on the query response. The currencyInputs are always the same and I put them in manually inside the listView.
The result you're getting is what I'd expect if you did {{[...'variable1.value', self.value]}} but as the code is written the spread operator should be seeing null or an array.
The code in currency2 definitely doesn't have quotes around the variable value?
Hey, got it working by adding [] as the default value for your variable. Dunno why mine worked without it but it makes sense as [...null] is not valid JS.
Thanks so much! Weird but it worked but I noticed it keeps adding to the array.. what I would love is if it is always static.. so the order of the array in the variable is the same as the order of the bids... ["Bid A", "Bid B", "Bid A", "Bid B"]... is that possible you think?
To set the bid values first set your variable default value to {} and then you'll need to use 'set in' and pass it an array of object keys to add the value.
Then when you need to convert to an array you'd just use Object.values(variable1.data.store_a).
That makes sense! Thanks for helping again! Just a quick question.. what if I don't know how many stores there will be... e.g. say theres a Store C and Store D as well.. would I put the key path to the query response?
That's where a list view component would be useful, with the result of your store query used as the source. The component will generate your currency containers in a quantity equal to the length of the query result.
You'd need to use some dynamic references in the children components using {{item}} and i but it's not too difficult to work out.
Yes I am using the listview component but just having a tough time getting all currency inputs from all the list views into an array and updating to my RetoolDB. Thats the last thing I have issues with. I wish Retool would let us use the components inside the listview in query but we can't. Thats the last thing holding me up... I simply want the bids from each store to be uploaded to my retoolDB but having issues with that