issue: "isDirty" and "dirtyFields" work incorrectly after calling "reset" or "setValue"

See original GitHub issue

Version Number

7.17.2

Codesandbox/Expo snack

https://codesandbox.io/s/elegant-goldberg-ebrms

Steps to reproduce

1st Use Case

  1. Go to https://codesandbox.io/s/elegant-goldberg-ebrms
  2. Click on ‘SET VALUE’ button
  3. See isDirty === false and dirtyFields is empty

2nd Use Case

  1. Go to https://codesandbox.io/s/elegant-goldberg-ebrms
  2. Click on ‘SET VALUE’ button
  3. Change Text field
  4. See isDirty === true and dirtyFields === {"text":true}

3rd Use Case

  1. Go to https://codesandbox.io/s/elegant-goldberg-ebrms
  2. Click on ‘RESET’ button
  3. See isDirty === false and dirtyFields is empty

4rd Use Case

  1. Go to https://codesandbox.io/s/elegant-goldberg-ebrms
  2. Click on ‘RESET’ button
  3. Change Text field
  4. See isDirty === true and dirtyFields === {"text":true}

Expected behaviour

1st Use Case isDirty should be true and dirtyFields should contain both fields

2nd Use Case isDirty should be true and dirtyFields should contain both fields

3rd Use Case isDirty should be true and dirtyFields should contain both fields

4th Use Case isDirty should be true and dirtyFields should contain both fields

Explanation: in all use cases the values are different from the default values, so the isDirty flag should be set to true and dirtyFields should contain all the fields that a different from the default values.

I believe this issue relates to the recently closed issue https://github.com/react-hook-form/react-hook-form/issues/6721 and the related discussion https://github.com/react-hook-form/react-hook-form/discussions/6710

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Code of Conduct

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Oct 12, 2021

case 3 is actually a bug, which incorrectly returns isDirty state, and not returning dirtyFields. I will try to patch that after work and do a release if possible.

0reactions
aantipovcommented, Oct 12, 2021

@bluebill1049 thank you very much for addressing the issue quickly! Could you please release a patch version?

Read more comments on GitHub >

github_iconTop Results From Across the Web

setValue() doesn't dirty the form · Issue #72 · react-hook-form ...
In this case, defaultValue doesn't work because I don't have data before calling the API so I have to use setValue to manually...
Read more >
React-hook-form doesn't set isDirty to false when back to initial ...
Shouldn't isDirty be set back to false when the form is back to its initial state and dirtyFields should be empty? Is it...
Read more >
useForm - unregister - React Hook Form
This method allows you to unregister a single input or an array of inputs. It also provides a second optional argument to keep...
Read more >
API Documentation - Simple React forms validation
By invoking useForm , you will receive the following methods register , unregister , errors , watch , handleSubmit , reset , setError...
Read more >
React Hook Form - What's the point of setValue if it doesn't do ...
When setValue is invoked for the first time and formState.isDirty is set to true. You can also set the shouldValidate parameter to true...
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