Custom State with multiple fields

Hi there!

Any idea how can I set a custom state with multiple fields?

I have a data type “Food” with two fields: “Type” and “Name”.
I would like to set a custom state called “Food temp” which will have a food type and a food name (that I gather from input fields on the page). The data type of the custom state will be “Food”.
I’m doing so because I don’t want to save this as a database thing until I have confirmation from the user. As soon as I have that confirmation from the user, I will add the " Food temp" custom state as a thing to the database.
The problem is how I create it as a custom state first…

Help?

A custom state doesn’t have fields. It just has a type and a value.

If your custom state data type is ‘Food’ then you can access all the fields of the ‘Food’ data type when referring to the state.

Note that when using a data type on a state, that will refer to ‘things’ from your database which already exist. The only way to create a new thing is by creating it in the database.

In your case, you’ll need to have 2 custom states (Food Temp Name + Food Temp Type), both of type ‘Text’. Then when you’re ready to create a new database entry of ‘Food’ you’ll set the fields to be the values of those text states.

Although, depending on how your setup is, there may not be any need to use states at all if you can just use the values of the inputs when you create your new ‘Food’.

1 Like

Thank you for your help Adam!