Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent isDirty state when resetting a form that's initialized with incomplete defaultValues #11541

Closed
1 task done
sebakerckhof opened this issue Feb 22, 2024 · 4 comments

Comments

@sebakerckhof
Copy link

Version Number

7.50.1

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/relaxed-hill-ss3fl6?file=%2Fsrc%2FApp.tsx

Steps to reproduce

  1. Fill in something in the form
  2. Click reset button
    -> formState.isDirty stays true

Expected behaviour

formState.isDirty to be false after reset OR formState.isDirty to be true after initializiation.

Note that the form is initialized with a partial defaultValues object (not all fields are part of the default values object). This results in a form state where isDirty is false, as expected.
After modifying a field and calling reset() the isDirty stays true. This only the case if not all fields are part of defaultValues. One could argue that the form state is different from the default values, since the field is not included in the defaultValues, and thus it should stay dirty. I wouldn't argue this since it's not what one would expect IMO. But still, if you go with that argument, then this means the form should already be dirty from the start.

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049 bluebill1049 added the status: under investigation aware of this issue and pending for investigation label Feb 22, 2024
@agustaf9
Copy link

I ran into the same issue, resetting the the form sets the dirtyFields to an empty object, so to check if the form is actually dirty I need to check the object entries length.

@bluebill1049
Copy link
Member

@bluebill1049 bluebill1049 added status: need more detail Please follow our issue template. and removed status: under investigation aware of this issue and pending for investigation labels Feb 24, 2024
@sebakerckhof
Copy link
Author

@bluebill1049
Copy link
Member

bluebill1049 commented Feb 24, 2024

missing lastName: "", for defaultValues

@bluebill1049 bluebill1049 removed the status: need more detail Please follow our issue template. label Feb 24, 2024
bluebill1049 added a commit that referenced this issue Feb 24, 2024
…reset` api

* related #11541 improve dirty check when undefined provided with reset api

* early exit when no values provided
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants