form.setData also sets form.initialData, meaning reset() doesn't work after setData

Is this the intended behaviour?
I have a form that I want to use for creating new records or editing existing records.
New record creation is fine, the form resets after submit.
I'm using setData to "load" existing data into the form for the user to modify. When you submit the form the data is updated but the form retains the edited record data. I can't then reset or empty the form back to defaults.

Steps to repro:

  1. Create a form with a text field
  2. Check the "reset on successful submit" option on the form
  3. Create a button that runs form.setData() and gives a value to the text field
  4. Check the value of form.initialData, should be ""
  5. Enter some data in the text field and submit, form resets the text field back to ""
  6. Click the button to run setData - text field should have the value you defined
  7. Check the value of initialData, it'll now be set to what you used in setData
  8. Click submit or call form.reset() and you will still have the setData value

What should I be using to "load" a form if it's not setData? thanks.

1 Like


Hey there :wave: Appreciate you writing in and pointing this out! I wrote up a bug report for this and tied it to this thread so I can update you right when progress is made :slightly_smiling_face: In the meantime, would you be able to use setValue() on the specific components in the form?

thanks - yea, I've worked around the issue by using setData with a temporary object that mirrors initialData

Just came across this problem too, was rather confused there for a bit so glad it's already been reported.


Just so you know the use case. I was populating a form based on a table row click and then allowing the user to edit the fields.

On submission of that form, I need to update the database but the ID of the record I'm updating is not an available field as it's not tied to any visible fields in the form.

Using form.initialData just seemed a tidy way of referencing that original ID.

Typically that would work but in this form I have a JSON object that needs updating hence the need to use form.setData which then overwrites the initialData property.

Hey @Ross_Coombes! Thanks for the +1 here. I've bumped this internally and can update you as I receive any more information.

A post was split to a new topic: Mobile Form - form.setData also sets form.initialData