How to do forms that edit an object?

repost from discord

Reuse a component

I have a a component that allows me to add data to the database, it consists of 1 dropdown menu, 4 input fields and then a submit button. The dropdown menu gets it’s information from a static array and then they are all connected to an object to store the data. From there, it goes through a few tasks but ultimately adds the data to the database.

Rather than creating the same layout again, can I reuse this but rather than add the data, get the data and edit the data? If so how do I go about it?

This is how I usually do forms that both create and edit an object. I create a component for the form, that takes an Id as input and connects the object to the input fields, and also have a Set Object Properties that store the data to the object when the Save button is clicked. Both use the same object id so you are essentially editing the object.

Here is an example of how I use the form:

And here is an example that does a full create, read and update. It’s a useful pattern for forms.

Hope this helps.

1 Like