Patterns

Forms

How Nacre forms ask, check and recover: labels that stay, errors that arrive at the right moment, and one place that lists everything to fix.

View as Markdown

Every field has the same four parts

A label above, the control, then one line under it that is either the hint or the error. The error takes the hint's place, so the form does not jump by a line when something goes wrong.

All six form controls share one error API. error is the message: it colours the control, sets aria-invalid and is linked with aria-describedby. invalid only marks the control, for the cases where a group or a summary owns the words.

  • Labels are always visible. A placeholder is an example of the format, never the label.
  • When most fields are required, mark the optional ones instead.
  • Every control takes ref as a plain prop, so a form can move focus to the field it is talking about.

Check on blur, then live

Nothing is wrong while someone is still typing. The first check runs when they leave the field. After that the field re-checks on every key, so the error goes away the moment the value is right.

Submit checks everything, including required fields that were never touched.

  • DoSay what to do: Enter a full email address, such as [email protected].
  • AvoidSay only what is wrong: Invalid input.
  • DoKeep the hint short enough that the error can replace it in the same place.
  • AvoidShow the hint and the error together under one field.
Invite by emailType part of an address and press Tab. Then finish the address and watch the message clear.

They get a link that works for seven days.

Summarise when the form is long

When a form is taller than the screen, a failed submit puts an error Alert at the top and moves focus to it. It names each problem as a button that moves focus to that field.

The summary is live: fixing a field removes its line straight away. When the last line goes, the Alert goes too.

New projectPress Create project with the form empty, then use the buttons in the summary to jump to each field.
Who can see it
Six people can open it.

One message for a group

A rule about a group, such as choose at least one, gets one message under the group instead of one per box. Each box is marked invalid, so it shows the error border and is announced as invalid, and the fieldset links the message.

  • DoPut the rule in the group's hint before anything goes wrong: Pick one or more.
  • AvoidReveal the rule only as an error after submit.
Mention notificationsPress Save preferences with nothing chosen, then tick any box.
When someone mentions you
At most one summary an hour.
Every mention from last week in one email.

Pick one or more.

Built with