reactive_forms icon indicating copy to clipboard operation
reactive_forms copied to clipboard

Clear errors without clearing the form

Open EzraBerendsen opened this issue 1 year ago • 1 comments

Is there a way to simply clear errors, without resetting the form?

The use case would be that a user is filling in a form, but accidentally presses a link that sends him to a new screen. When the user presses the back button the form is shown again with the values filled in currently, but they also see errors.

So basically I'd like a clearErrors functionality on the form instance to clear all the errors on the form.

Right now the only thing that comes close is:

form.reset();
form.errors.clear();

But like I mentioned, I don't want to clear the form, just the errors.

I also tried using form.setErrors({});, but this seems to recalculate what errors there should be based on current input inside the fields(?)

EzraBerendsen avatar Mar 15 '23 12:03 EzraBerendsen

try

form.reset(
  value: form.value,
  removeFocus: true,
)

vasilich6107 avatar Mar 17 '23 09:03 vasilich6107