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
{{ message }}
Repository navigation
isDirty should flip back to false when default values are equal #1080
Tanstack Form already exposes the isTouched property which can be used to determine if the form has been touched. It appears right now that both isTouched and isDirty now have the same behavior. Except when you reset the form, dirty returns to false as expected.
In your example if you add the isTouched prop with your isDirty flag, isTouched will change to true when you focus the input and then remove focus from the input field (without changing the value).
In your example if you add the isTouched prop with your isDirty flag, isTouched will change to true when you focus the input and then remove focus from the input field (without changing the value).
That's not what I'm referring to.
Even the docs say:
and "dirty" after the value has been changed
Changed, not modified.
A-B (the value has changed. I.e it's dirty)
A-B-A (the value hasn't been changed, i.e not dirty, but touched)
If the field returns to its original value, is it still dirty? All libraries I've worked with so far says no, it's only touched. Dirty is only true if the values differ from the initial value(s).
I'm not a maintainer so not sure for their reasoning but just wanted to point you to the right spot for the different lifecycles. Under the image of that link for field-state they say:
the isDirty flag in TanStack/form is different from the flag with the same name in RHF.
If you want to keep the issue open and talk to them about why that is the case that is fine. Just wanted to point you in the right direction!
Yeah I think it warrants a discussion. I'd love to hear the reasoning behind this deviation, as the behavior of isDirty seems to be a well established in many well known form libraries. I'll reopen this as a question instead.
Activity
thazlett16 commentedon Dec 17, 2024
This is documented in the field-state section.
In your example if you add the
isTouchedprop with yourisDirtyflag,isTouchedwill change totruewhen you focus the input and then remove focus from the input field (without changing the value).alexqhj commentedon Dec 17, 2024
That's not what I'm referring to.
Even the docs say:
Changed, not modified.
A-B (the value has changed. I.e it's dirty)
A-B-A (the value hasn't been changed, i.e not dirty, but touched)
If the field returns to its original value, is it still dirty? All libraries I've worked with so far says no, it's only touched. Dirty is only true if the values differ from the initial value(s).
thazlett16 commentedon Dec 17, 2024
I'm not a maintainer so not sure for their reasoning but just wanted to point you to the right spot for the different lifecycles. Under the image of that link for
field-statethey say:If you want to keep the issue open and talk to them about why that is the case that is fine. Just wanted to point you in the right direction!
alexqhj commentedon Dec 17, 2024
Yeah I think it warrants a discussion. I'd love to hear the reasoning behind this deviation, as the behavior of
isDirtyseems to be a well established in many well known form libraries. I'll reopen this as a question instead.devth commentedon Jan 17, 2025
Discussion continues at #1081 (I have the same question).