isDirty is true for objects inside fieldArray elements before changes
See original GitHub issueDescribe the bug
When using useFieldArray
with an array of objects, containing nested objects, dirtyFields
will be true
for the nested object as soon as it is added, before any of its children have been changed.
To Reproduce Steps to reproduce the behavior:
- Go to the below Codesandbox
- No fields are currently dirty (as shown in the screenshot below)
- Click ‘Add User’
- Dirty fields is now:
[
{
"details": true // Expected: false
}
]
- Fill out either (or both) of the inputs
- Dirty fields is now (if both filled out):
[
{
"details": {
"first": true,
"last": true
}
}
]
Codesandbox link (Required) https://codesandbox.io/s/infallible-wave-kg5z4?file=/src/App.js
V7.6.7
Expected behavior I would expect either of the following:
details
to befalse
- as I have not modified any of its child fields yetdetails
to be{ first: false, last: false }
- as it should know about the child fields already as they have beenregister
ed
Screenshots
Desktop (please complete the following information):
- OS: Windows 10
- Browser Chrome
- Version 90
Additional context N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
issue: Form isDirty doesn't always match dirtyFields #7970
Issue 1. At this point, you'll see the overall form isDirty = false and dirtyFields has true values within it.
Read more >react-hook-form isDirty seems weird for me - Stack Overflow
I expect isDirty should be true only when value of input element changes. Is that normal in react-hook-form? // I had to make...
Read more >Initializing From State - Redux Form
To keep dirty form values when it reinitializes, you can set keepDirtyOnReinitialize to true. By default, reinitializing the form replaces all dirty values ......
Read more >Form - Ant Design
High performance Form component with data scope management. Including data collection, verification, and styles.
Read more >FormArray - Angular
It accepts an array that matches the structure of the control, and does its best to match the values to the correct controls...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
updated: https://github.com/react-hook-form/documentation/commit/bbd8afb5805bb5f44adeaa2decdb39b16463b494
definitely a good idea. I will get that updated.