Skip to content
Focsd homeFocsd homeFocsd
Forms

Error summary

Lists every error after a failed submit and links to each field. Inside a form it validates on its own.

  • Tag: focsd-error-summary
  • Pattern: Alert with links to fields
  • Category: Forms

Example

Create team
HTML
<form class="stack" method="dialog">
<focsd-error-summary></focsd-error-summary>
<focsd-text-field
name="team"
label="Team name"
required
error-message="Enter a team name"></focsd-text-field>
<focsd-text-field
name="email"
type="email"
label="Work email"
required
error-message="Enter an email address, like [email protected]"></focsd-text-field>
<focsd-button type="submit" variant="action">Create team</focsd-button>
</form>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-error-summary.js';
</script>
<focsd-error-summary></focsd-error-summary>

API

Attributes

AttributePropertyTypeDefault
headlineheadlinestring—
manualmanualbooleanfalse

JavaScript properties

PropertyTypeDescription
manualbooleanTurn off automatic validation. By default a summary inside a form (or tied to one with form="id") checks every field on submit, shows each field's error-message, lists the errors and stops the submit.
errors{ field: string, message: string }[]The errors listed. Filled for you in automatic mode; set it (or call collect()) yourself with manual, for example for errors from a server.

Methods

MethodDescription
collect(form)Fill errors from every control (or focsd-field) in the form that has a non-empty error, in tree order. The error property is read first, so an error set in the same task (not yet reflected) counts; the attribute covers elements without the property. Candidates are the form's elements (including controls tied to it with form="…") and every [error]. Fields without an id get one, so the links can reach them.

CSS parts

Style the inside of the component with ::part(), for example focsd-error-summary::part(headline).

PartDescription
headlineThe headline element.
linkEach link to a field with an error.
listThe list element.
summaryThe summary box.

Accessibility

  • role="alert" and tabindex="-1": it takes focus on a submit with errors, so the problem is announced. It does not move focus while a fix shortens the list.
  • Each error is a link that moves focus to its field (works with shadow-DOM fields).
  • Each field shows its own error too (a 1px critical border, an icon and the message), so the error never relies on color or on the summary alone.