final-form / final-form

🏁 Framework agnostic, high performance, subscription-based form state management

Home Page:https://final-form.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resetting a form doesn't clear meta.modified

ArnaudWeyts opened this issue · comments

Are you submitting a bug report or a feature request?

Bug report

What is the current behavior?

The meta.modified field does not get reset anymore after manually calling form.reset or form.initialize.

In the sandbox below; type something in the input and submit it, you'll see from the console logs that after the reset, meta.modified is still true.

What is the expected behavior?

The meta.modified field is set to false after resetting.

Sandbox Link

https://codesandbox.io/s/practical-grothendieck-72vgp

What's your environment?

Introduced in final form version 4.18.7

Other information

I suspect this is due to the changes from #301

For what it's worth, I am seeing that meta.touched is also not being reset.

Came here to report meta.touched and meta.error not being reset on the field level when form.reset() is called.

I think the problem comes from the publishFieldState function, in here only the pristine is being changed based on the previous and current value.

form.reset() should reset everything.

@chillyistkult I agree. I'm not so sure it should reset submitErrors (FORM_ERROR), though. It'd be nice if that could be controlled by an argument.

I have the same problem with version 4.18.7. Using form.reset doesn't clear meta.error of Field component. Issue could be solved downgrading to version 4.18.6.

I ran into the same problem and came here to post an issue. To illustrate the problem, I created a sandbox by forking the final form example with row-level validation. You can see the sandbox here: https://codesandbox.io/s/green-wave-8q1c9 I was finally able to get the expected behaviour by following @ArnaudWeyts example and then adding form.resetFieldState('firststname') and form.resetFieldState('lastname') to the onSubmit() function (lines 16 and 17 in the sandbox app). The two lines are commented out in the sandbox so the the problem is apparent when you fill in and submit the form - the validation errors appear on the empty form because the meta.touch attribute is still true even though form.reset() has been called. Adding resetFieldState() for each field in my form seems like a bit of hack, but it does seem work. I would be interested if anyone has a more general solution or can find another problem with my code that could be causing the issue. I'm using 4.18.7 and have not tested 4.18.6 as suggested by @skoob13.

I think #348 should take care of this. The new API method restart has landed on master and is documented: 301a976.