Replies: 1 comment
-
I see this was mentioned earlier and marked as "works as designed" (#11402). Solution: build your own logic which decides what is considered dirty. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a usecase where I render a complex form which relies on useFieldArray. Everything works as expected, except for how isDirty is handled by RHF by default.
Whenever a change to a nested field is made, the field is marked as dirty. This is the expected behavior.
However, when a field is added or removed, the entire array is marked as dirty, since it diffs from the defaultValues where, say, starting array had 10 objects, and the user removed one, so RHF marks all objects as dirty.
What I need is a way to avoid this default behavior. All fields are not dirty, just because a user deleted one field.
Note that this works as intended for nested fields (Person A has 3 books from the start, adds one book, only that newly added book is marked as isDirty).
However, if a whole new person is added (Person B), then all other Persons and all of their books are marked as dirty. The same goes for removal, if starting with Person A, B and C, and they each have, say 5 books (a book being an object with Name and other props), when a person is removed, all other person and their books are marked as isDirty.
How have you dealt with this? Ditch isDirty and track your own state changes?
Beta Was this translation helpful? Give feedback.
All reactions