Error summary
Lists every error after a failed submit and links to each field. Inside a form it validates on its own.
Example
<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 <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>import { ErrorSummary } from '@focsd-dev/react';
export function Example() { return <ErrorSummary></ErrorSummary>;}<script setup>import '@focsd-dev/components/focsd-error-summary.js';</script>
<template> <focsd-error-summary></focsd-error-summary></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-error-summary.js';
// template<focsd-error-summary></focsd-error-summary><script> import '@focsd-dev/components/focsd-error-summary.js';</script>
<focsd-error-summary></focsd-error-summary>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
headline | headline | string | — |
manual | manual | boolean | false |
JavaScript properties
| Property | Type | Description |
|---|---|---|
manual | boolean | Turn 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
| Method | Description |
|---|---|
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).
| Part | Description |
|---|---|
headline | The headline element. |
link | Each link to a field with an error. |
list | The list element. |
summary | The summary box. |
Accessibility
role="alert"andtabindex="-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.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.