reactive_forms
reactive_forms copied to clipboard
Clear errors without clearing the form
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(?)
try
form.reset(
value: form.value,
removeFocus: true,
)