`formState.isDirty` is true even though no field is really dirty
See original GitHub issueDescribe the bug When setting values on a form for which there are no related fields for, the form stays dirty after reverting these values back to their original state.
To Reproduce Steps to reproduce the behavior:
- Click on ‘Clear’ button
- Click on ‘Revert’ button
- Click on ‘Submit’ button
- In the console i compare the
defaultValueswith the values the form submits. They are totally equal!formState.isDirtyis true,formState.dirtyFieldsis an empty object.
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-useform-template-forked-q3iw3?file=/src/index.js
Expected behavior
When the current values of the form equals the defaultValues, formState.isDirty must be false.
Desktop (please complete the following information):
- OS: macOS Mojave Version 10.14.6 (18G5033)
- Browser: Google Chrome Version 88.0.4324.96 (Official Build) (x86_64)
Additional context
Besides the only form field called “nickname” in the example provided, there is an additional operations variable in the defaultValues object (which is not a field, only data) which also gets updated in the example by using setValue. The issue is related to that variable. If i remove the operations thingy, the example works fine without any issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top Related StackOverflow Question
Sure sure 👍 Thank you, have a good weekend as well 🥳 And thanks again. Appreciating your fast and detailed responses.
No worries at all, please don’t take the message in a negative way. I think it’s a general message when an issue sends to the maintainer, we expect the example can be a bit more straightforward, at the same time I understand the complexity within your or everyone’s app. I hope you understanding where I am coming from, and I thank you for your understanding too. ❤️ have a good weekend.