Capítulo 7 de 39

Chapter 7: clearErrors

Core Idea

clearErrors(name?) manually removes validation error state — one field, several by name, or the entire form — without touching validation rules or formState.isValid.

Key Concepts

  • No argument: clears every error.
  • String: clears one field, or a whole namespace at once — clearErrors("test") clears both test.firstName and test.lastName if both were registered under test.*.
  • String[]: clears exactly the listed fields.
  • Does not affect isValid: clearing an error doesn't re-run validation or recompute formState.isValid; that only happens on the next real validation trigger.

Code Examples

clearErrors("firstName")               // one field
clearErrors(["firstName", "lastName"])  // several fields
clearErrors()                           // everything
  • What it demonstrates: the three call shapes, from narrowest to broadest.

Anti-patterns

  • Expecting clearErrors to make isValid true: it only removes displayed error state; isValid is only ever set by an actual validation pass.

Key Takeaways

  1. clearErrors("namespace") clears every error under that namespace, not just an exact match.
  2. Clearing errors is purely a display-state operation — it doesn't validate or revalidate anything.

Connects To

  • useform-seterror: the inverse operation.
  • useform-formstate: where errors/isValid actually live.