foxhound87 / mobx-react-form

Reactive MobX Form State Management
https://foxhound87.github.io/mobx-react-form
MIT License
1.09k stars 129 forks source link

Clear hasError state when resetting? #613

Closed jacobweberbowery closed 1 year ago

jacobweberbowery commented 1 year ago

Hi. I have a form where all fields are required, and their default values are empty. I'm using hasError in my bindings to indicate which fields have errors.

I don't want errors to appear until the user at least focuses a field, so I set validateOnInit: false.

But when I reset the form to its initial values using form.reset(), I want to put it back in that initial state, so the errors no longer appear.

I tried setting showErrorsOnReset: false, and this prevents the error text from appearing. But the hasError property still becomes true. Is there a way to prevent this?

nickryall commented 1 year ago

I have the same issue. A workaround we use for now is

form.reset();
form.each(field => field.resetValidation());
foxhound87 commented 1 year ago

resetValidation() is now performed on reset and clear instead of validate()

Also introduced validateOnClear & validateOnReset form options (disabled by default).

jacobweberbowery commented 1 year ago

Thanks!