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

Imperative api reset() caused form onChange event fired for each field.

Open huangc8606 opened this issue 5 years ago • 1 comments

For example I have a form with 3 input fields, then call formsy.reset({}), onChange event will be fired 3 times(each field will trigger one onChange event on Formsy component), so if I have 10 fields, onChange will be fired 10 times if I use reset function. And I believe this reset process should be batched and fire onChange event only after all fields' value are updated. https://github.com/formsy/formsy-react/blob/master/src/Formsy.ts#L243

I added below if you click "Reset Model" you could see 3 lines output. https://codesandbox.io/s/react-playground-6m7if?file=/index.js

huangc8606 avatar Aug 08 '20 14:08 huangc8606

Debug info, When calling reset() the following chain is triggered:

reset() -> forEach(input).resetValue -> input.setState(prestine) -> validate -> onChange

Looks like the flag canChange is not solving the issue.

felixmosh avatar Aug 27 '20 16:08 felixmosh