Unexpected `onFirstChange` behavior with regard to `Form.reset()`
See original GitHub issueEnvironment
- OS: macOS High Sierra 10.13.6
- Node: 10.10
- NPM: 6.4.1
- react-advanaced-form: 1.6.7
What
Current behavior
- Provide a Form component with an
onFirstChange
callback. - Change a field in the form.
- The callback passed to
onFirstChange
is invoked. - Call the form’s
reset()
method. - Change a field in the form again.
- The callback passed to
onFirstChange
is not invoked.
Expected behavior
I would personally expect a form that has been reset to no longer be dirty.
My use case is a user profile form. It is only submittable when the form is dirty. After it is successfully submitted and updated via the server I call Form.setValues()
and Form.reset()
. Currently I can’t figure out a way to track its dirty state after past point.
Why
The only place the Form’s dirty
state property is ever set to false
is in the constructor.
https://github.com/kettanaito/react-advanced-form/blob/master/src/components/Form.jsx
It seems like either a design decision or an oversight. If it’s intentional I’m just looking for a way to handle my use case. Otherwise I’m happy to submit a PR to update this behavior.
How
Here is a CodeSandbox demo: https://codesandbox.io/s/k54v4r9mvo
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
Thanks for the quick response!
I’ll open a PR today for the fix to
reset()
.And your response regarding
initialValues
makes sense. Your proposed solution will work for me.Fixed in #373. Will be published in the next patch version.