Replies: 2 comments
-
I really think the current behavior of I mean, if Therefore, the current behavior of |
Beta Was this translation helpful? Give feedback.
-
i just run into this and think there should be a way to check for a changed form state. Either change isDirty or add isModified or isChanged as alexqhj suggested. |
Beta Was this translation helpful? Give feedback.
-
isDirty
flips totrue
when you change any form value, but doesn't return tofalse
when the state returns back to default values.I'm unsure about the reasoning for this behavior.
Here's an example using Tanstack Form.
https://stackblitz.com/edit/tanstack-form-1cspfar1?file=src%2Findex.tsx
The docs specify:
But there's no explanation of the reason for this choice. But it was apparently unusual enough to warrant its own note in the docs.
If
isDirty
can't, or won't be changed, perhaps there's a way to expose a value indicating that the form is no longer in its default state. This is very useful for disabling submit buttons for example.For most if not all form libraries I've used, the expected behavior is the form is not dirty when the default values is equal. See formik example here:
https://stackblitz.com/edit/react-hooks-form-validation-example-formik-hh9rdieb
Perhaps it would be appropriate to
Option 1: Return
isDirty
to it's well known behavior of returning tofalse
when the form is at its default values.Option 2: As option 1, but
isPristine
is no longer a mirror ofisDirty
, but ratherisPristine
will be false when any change to the form has been made.Option 3: Expose a new property, like
isModified
orisChanged
to indicate that the values differ from the default/initial values.Beta Was this translation helpful? Give feedback.
All reactions