`formState.isDirty` is true even though no field is really dirty

See original GitHub issue

Describe 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:

  1. Click on ‘Clear’ button
  2. Click on ‘Revert’ button
  3. Click on ‘Submit’ button
  4. In the console i compare the defaultValues with the values the form submits. They are totally equal! formState.isDirty is true, formState.dirtyFields is 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:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
delijahcommented, Feb 6, 2021

Sure sure 👍 Thank you, have a good weekend as well 🥳 And thanks again. Appreciating your fast and detailed responses.

1reaction
bluebill1049commented, Feb 6, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

isDirty changing to true when no field is actually dirty #3213
I cannot see a value for isDirty after upgrading to v6, even if I have empty default values and I reset all the...
Read more >
React-hook-form doesn't set isDirty to false when back to initial ...
When you change back to the original value, isDirty remains true, because ALL of the default values don't match the form input values...
Read more >
Final Form Docs – `FormState`
An object full of booleans, with a value of true for each dirty field. ... be invalid even if the errors do not...
Read more >
getFieldState - React Hook Form
Performant, flexible and extensible forms with easy-to-use validation.
Read more >
React Hook Form - useForm: formState - YouTube
This session cover formState API inside react hook form.Doc: https://react-hook-form.com/api/useform/ formstate.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found