[Forms] Best Practices for Forms and Inputs

Hi all!

I have some questions…

My app has a Form Container with some inputs. So far, so good.

I wanted to know what is the best practice for interacting with forms:

  1. Is it better to have a form to create a new product and another to edit the product or do I just use one form to handle both cases (using variables and conditionals)?

  2. Do I configure the inputs to change a variable in the “onchange” and then update the backend or do I get the value directly from the inputs when saving?

  3. In the database I have an array of objects with “question” and “answer” keys and how do I load the number of entries referring to this object?

  • If I link to the array I lose the input variables.

I ask all this because I noticed something that could help the community: What if the Form container had a built-in variable that would be an object of all inputs where the keys would be labels (or placeholders) and the values ​​would be the responses. Does this make sense to any of you?

Thanks in advance!

  1. Depends on the complexity and difference between two, I think it’s completely fine having two separate ones
  2. You can just use the Form submit workflow and use the exposed input values
  3. Do you mean the number of objects in the array?
1 Like

Hi!

Thank you for the responses.

Regarding question 3, in my DB I have an array of objects:

[
  {
    "question": "A",
    "answer": "aaa"
  },
  {
    "question": "B",
    "answer": "bbb"
  }
]

If I bind this array to a form container, I lose the input variables that are inside this container.

My question is how to update the object with the values ​​of these inputs? Or do I create a separate “mini form” to change that item in the object, leaving it unbinded? :thinking:

Thank you again! :grin:

I recommend using the same form, even to facilitate maintenance. To do this, you can use a control variable like isEdit (true/false) and depending on the value of the variable you adjust it.

Regarding having inputs inside the list, you need to create an auxiliary variable (array) and set the value in this variable as each input is changed in the onChange event and taking the event value of each input and setting it in the variable.

1 Like