formsy-react
formsy-react copied to clipboard
Add global Formsy.isPristine() function
It would be really useful to be able to use isPristine in the component that has the <Formsy/>
, for example for when you want to enable submit only when form is dirty. Right now we need to track the dirty state of the form ourselves. We have isPristine only inside the input component (with.Formsy).
Is this request align with Formsy intended design? Would a PR be welcome for this?
A pull request would be very welcome for this feature.
Had the same question today and that value is kinda there. Formsy pass two properties to onChange
callback - current form values and result of internal func isChanged
, which actually does what we need - checks whether any input value has changed.
See https://github.com/formsy/formsy-react/blob/master/src/index.ts#L395
If we renamed isChanged
to isPristine
and added it to API.md
does that solve this feature?
A test would be nice too, if it became a publically documented function.
You should probably think about dynamically added/removed fields too. isChanged
returns true if you add/remove fields dynamically, since default state for all new fields is pristine, though, is whole form still pristine? It's a philosophical question :)