formsy-react icon indicating copy to clipboard operation
formsy-react copied to clipboard

Add global Formsy.isPristine() function

Open eranshabi opened this issue 7 years ago • 4 comments

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?

eranshabi avatar Jan 21 '18 10:01 eranshabi

A pull request would be very welcome for this feature.

rkuykendall avatar Feb 22 '20 20:02 rkuykendall

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

hafnis avatar Feb 28 '20 13:02 hafnis

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.

rkuykendall avatar Feb 28 '20 14:02 rkuykendall

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 :)

hafnis avatar Feb 28 '20 14:02 hafnis