jquense / react-formal

Sophisticated HTML form management for React
http://jquense.github.io/react-formal
MIT License
526 stars 52 forks source link

Validation delay is not synchonized with submit #120

Open cventus opened 7 years ago

cventus commented 7 years ago

I have a form that can be submitted many times. When a submission is successful the form is cleared out and the user is free to fill it in again.

The form contains a text field which is required. If the text field has focus when I press the submit button it loses focus and the onBlur event schedules the field to be validated after a 300ms delay. If the submission is very quick then the form is cleared out before the delayed validation happens and I end up with an error message next to the now empty field saying that it is required, even though everything actually went well.

Since validation occurs before onSubmit/onInvalidSubmit is called, I expected that to be enough and not for the delayed field validation to linger. Generally, any time the whole form is validated there should be no need to validate again unless something changes. I don't see a way to cancel the timeouts myself nor any way to reliably wait for them before clearing out the form.

Looking at src/Form.js, maybe the flush-validations timeout could be cleared in submit()?

jquense commented 7 years ago

that seems reasonable yeah. If you want to put a PR together we can see if it causes any issues