#Reset form level errorMap

15 messages · Page 1 of 1 (latest)

azure dagger
#

I'm trying to figure out how to reset all form level errors, e.g. form.errorMap and form.errors but can't seem to find a method for that. setErrorMap seems only closest thing, but it doesn't allow resetting errors.

Any ideas?

acoustic shore
#

also, what do you intend to use it for?

azure dagger
#

it does accept setErrorMap({}) but it doesn't do anything.
i have a form with steppers. I need to reset the form on moving to a new step

acoustic shore
#

a form.reset() could also be a clean approach if it's a stepped form. If you keep defaultValues as external state to make sure it contains the latest saved data

azure dagger
#

yeah it seems like forn.reset() could help if i pass the data back to it from somehwere else.

Does one with every key set to undefined work?
every key, meaning onSubmit, onBlur etc?

no, it doesn't, as passing empty object to those handlers still makes them appear in errorMap with empty value

acoustic shore
azure dagger
#

yeah that was the first thing i tried, didn't help\

#

actually, seems like passing undefined does the trick! i tried with {} / []

#

thanks 🙂

acoustic shore
#

I could've sworn that this was done internally at some point, but good to hear it's not broken on the outside

#

well, a little bit broken.

azure dagger
#

yeah just need to pass to each key explicitly