You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/framework/react/guides/basic-concepts.md
+27-4Lines changed: 27 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,17 +92,40 @@ const {
92
92
} =field.state
93
93
```
94
94
95
-
There are three field states that can be useful to see how the user interacts with a field: A field is _"touched"_ when the user clicks/tabs into it, _"pristine"_ until the user changes value in it, and _"dirty"_ after the value has been changed. You can check these states via the `isTouched`, `isPristine` and `isDirty` flags, as seen below.
95
+
There are three states in the metadata that can be useful to see how the user interacts with a field:
96
+
97
+
-_"isTouched"_, after the user clicks/tabs into the field
98
+
-_"isPristine"_, until the user changes the field value
99
+
-_"isDirty"_, after the fields value has been changed
> **Important note for users coming from `React Hook Form`**: the `isDirty` flag in `TanStack/form` is different from the flag with the same name in RHF.
104
-
> In RHF, `isDirty = true`, when the form's values are different from the original values. If the user changes the values in a form, and then changes them again to end up with values that match the form's default values, `isDirty` will be `false` in RHF, but `true` in `TanStack/form`.
105
-
> The default values are exposed both on the form's and the field's level in `TanStack/form` (`form.options.defaultValues`, `field.options.defaultValue`), so you can write your own `isDefaultValue()` helper if you need to emulate RHF's behavior.`
107
+
## Understanding 'isDirty' in Different Libraries
108
+
109
+
Non-Persistent `dirty` state
110
+
111
+
-**Libraries**: React Hook Form (RHF), Formik, Final Form.
112
+
-**Behavior**: A field is 'dirty' if its value differs from the default. Reverting to the default value makes it 'clean' again.
113
+
114
+
Persistent `dirty` state
115
+
116
+
-**Libraries**: Angular Form, Vue FormKit.
117
+
-**Behavior**: A field remains 'dirty' once changed, even if reverted to the default value.
118
+
119
+
We have chosen the persistent 'dirty' state model. To also support a non-persistent 'dirty' state, we introduce the isDefault flag. This flag acts as an inverse of the non-persistent 'dirty' state.
@@ -626,6 +626,10 @@ export type DerivedFormState<
626
626
* A boolean indicating if none of the form's fields' values have been modified by the user. Evaluates `true` if the user have not modified any of the fields. Opposite of `isDirty`.
627
627
*/
628
628
isPristine: boolean
629
+
/**
630
+
* A boolean indicating if all of the form's fields are the same as default values.
631
+
*/
632
+
isDefaultValue: boolean
629
633
/**
630
634
* A boolean indicating if the form and all its fields are valid. Evaluates `true` if there are no errors.
0 commit comments