# Errors and validation

Telling someone a value isn't valid, or that something went wrong, in words that say what to do.

## When it applies

- A field's value isn't valid when the form is saved, or a check on it fails as they type.
- Something on the page is wrong and stays wrong until it is fixed, like a mailbox that isn't connected. No example screen shows this yet.
- Something the person just did failed. No example screen shows this yet.

## Components

- [Field](../components/field.md): A control's `error`, under it.
- [Input](../components/input.md): `validation`, for a check that takes a moment.
- [Alert](../components/alert.md): A condition on the page that stays until it's resolved.
- [Toast](../components/toast.md): An action that just failed.
- [Checkbox](../components/checkbox.md): `aria-invalid`, with the message in text near it.

## Rules

- Do: Write a field's `error` as what to do, in the form "Please enter a valid email". It appears without moving the form and is announced.
- Do: Set `invalid` with no message on a field whose partner holds the error, like a start time when the end time says it must be later.
- Do: Use `Input`'s `validation` for a check that takes a moment, like whether an email is already on a contact, and put what to do in the `Field`'s `error`.
- Do: Use `Alert` for a condition that stays until it's resolved, with the fix in `action` as a `TextLink`. Write it as what happens next or what to do.
- Do: Write a failed action's toast description as what to do, like "Please check your connection and try again."
- Don't: Show an error by colour alone. The red edge comes with the message, and a warning or an error says which it is in its title.
- Don't: Use a toast for something a person must act on later. It leaves on its own; use `Alert` in the page.
- Don't: Dim a field yourself with opacity. Set `disabled`, which disables the control and dims the whole field together.

## See it

- [Form panel](../screens/example-form-panel.md): A form in a panel over the list: fields in one column, pairs side by side, and Cancel and Save in the panel's footer.
- [Settings page](../screens/example-settings-page.md): Settings on the grey page surface: a 240 px menu of sections, and the chosen section beside it under its own title.
