Populating multiple inputs by selecting option from select component

  • Goal: I am trying to build an order page, where the End User selects a product and then it can be added to a cart.

  • Steps: I currently have a select that displays data from a retool database, specifically a description, and retrieves the "code" (part number) from the same database on selection. I then have a button which runs the following when clicked:
const id = CreateOrder_NewProductSelect.value;
const quantity = CreateOrder_NewProductQuantityInput.value;
const itemIndex = getProducts.data.id.indexOf(Number(id))
const title = getProducts.data.title[itemIndex]

createOrderCart.setValue([{ id, title, quantity }, ...createOrderCart.value]);

What I am trying to achieve is the ability to send any of the data from the database after its been chosen in the select to the "cart"

Hi @Jack_Thompson,

Thanks for reaching out. So far, what you've described makes sense to me!

What I am trying to achieve is the ability to send any of the data from the database after its been chosen in the select to the "cart"

It seems like the createOrderCart is correctly storing the state of the cart, like you intended. Are you having trouble persisting this variable? If so, I would suggest creating a new table in Retool DB to represent a user's cart, and then writing to that table on click instead of storing it to the createOrderCart variable.

When you want to display/reference the user's cart, you can create a different query to read from that new DB table.

Hope this helps!

1 Like