What is the pattern to delete form fields such that isDirty
is updated to true
?
#10784
Unanswered
paulleonartcalvo
asked this question in
Q&A
Replies: 2 comments
-
I'm also running into this issue. Any guidance @bluebill1049 ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I might be misunderstanding your requirement, but you can pair the useForm({
values,
resetOptions: {
keepDefaultValues: true
}
}) |
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 form:
which is built dynamically. Users can click an
Add
button, and choose a field (fieldA
,fieldB
,fieldC
,...) to add. I am passingvalues
from my filter component'sprops
into theuseForm({values: values})
. I use a separateuseState
array to track which fields to render. Then i render each field with a<Controller .../>
withshouldUnregister
set totrue
. The user should be able to delete each field as well, and its entry should be removed from the form. For example, if a user deletesfieldA
from the array above, the resulting form should be:However, i notice that even after
fieldA
's<Controller/>
is unregistered (since it is no longer rendered), the form'sisDirty
does not change totrue
. Why is this? How can i change my implementation, or what is the generally used pattern such that deletion/unregistration results in theisDirty
changing to true? Is there a different way to achieve my expected behavior? I expected that ifcurrentForm.deepEquals(props.values) === false
, then the form is dirty, but this appears to not be the case.Beta Was this translation helpful? Give feedback.
All reactions