Forms guide · 2 of 8
When errors show
The schema always runs. showErrors only decides when an error becomes visible, and every mode shows everything after a submit.
Modes showErrors
Each field below uses a different mode. Type something wrong in each one and leave it, then compare when the errors appear. edited, the default, waits until a field has been changed and left, so passing over an empty field says nothing.
'edited': once the field has been changed and left.'blur': once the field is left, even unchanged.'input': as soon as the value changes, or once the field is left.'submit': only after the first submit.
A mode per field showErrors
Give a mode per path, with default for the rest. A group covers everything under it, and the nearest path wins. A row added to a list after a submit stays quiet until it is left, or until the next submit.
useForm({
schema,
showErrors: { default: 'edited', username: 'input', members: 'submit' },
})An error summary errorListallErrors
errorList holds the errors that are showing, with their paths, for a summary at the top of a long form. allErrors holds every error, shown or not. Submit this form empty.
Errors that move the page
An error that appears pushes the content below it down. vael-form waits for a mouse or touch press to be released before it marks a field as left, so a click on a button that then moves still lands. To stop the shift itself, keep the error element in the page and give it a min-height. aria-describedby points at it only while the field is invalid.
<p :id="attrs.email.errorId" class="error">{{ errors.email }}</p>
<style>
.error {
min-height: 1.5em;
}
</style>Autofill
A browser that autofills a form plays back focus, input and blur on each field in a few milliseconds, at your first click on the page. That blur isn’t you leaving the field, so an autofilled field shows no error until you type in it or submit.
For the whole app formPlugin
Install the plugin once to set the mode for every form. A form’s own showErrors replaces it; the two aren’t merged. field.untouch() hides a field’s errors again until it is left once more.
// main.ts
import { formPlugin } from 'vael-form'
app.use(formPlugin, { showErrors: 'blur' })