- Docs
- Remove errors with clearErrors()
Remove errors with clearErrors()
Removes manual errors set with setErrors() for every field or a list of fields. Validation errors from your rules are not touched.
Removes manual errors. Validation errors from rules are not touched.
Signature
clearErrors(): FormController
clearErrors(fields: string[]): FormController
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
fields |
string[] |
no | When provided, only the listed fields are cleared. When omitted, every manual error is cleared. |
Returns
The same FormController — chainable.
Behaviour
- Only manual errors (set via
setErrors) are removed. Validation errors from rules are recomputed the next time validation runs. - Visual attributes are re-synced for the affected fields —
css-erroris removed when no errors remain for a field. - Subscribers are notified.
Examples
Clear a single field
import { form } from '@samline/forms'
const profile = form('profile-form')
profile.setErrors({ email: ['Already in use.'] })
profile.clearErrors(['email'])
Clear everything
profile.setErrors({
email: ['Already in use.'],
password: ['Too weak.'],
})
profile.clearErrors()
Clear before re-running validation
profile.clearErrors()
profile.validate()
Edge cases
- Validation errors are not cleared by
clearErrors. They live in a separate map and are only cleared byresetor by a successful re-validation of the field. clearErrorson a field with no manual error is a no-op — the chain still returns the controller.- Passing an empty array
clearErrors([])does nothing. UseclearErrors()to clear everything.