Form
Form container with validation timing, an error summary, server errors, dirty tracking and async submit.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
validate-on | FormValidateOn | submit | When an error first shows, for every field inside: submit, blur or input. A field's own validate-on wins. |
necessity | FormNecessity | required | Marker style of every field inside: required (asterisk), optional ("Optional") or none. A field's own necessity wins. |
error-summary | FormErrorSummary | auto | auto: a summary above the form for two or more errors, focus on the control for one. always: a summary for one too. none: never. |
errors | FormErrors | {} | Server errors keyed by control name, e.g. {"email": "Already registered"}. Each one clears when its control is edited. |
warn-unsaved | boolean | false | Asks before the page unloads while the form has unsaved changes. |
Slots
| Name | Description |
|---|---|
default | The native <form>. |
error-summary-heading | Replaces the summary heading ("There are 2 problems with this form"). |
Events
| Name | Type | Description |
|---|---|---|
valid-submit | CustomEvent<ValidSubmitEventDetail> | Every control is valid and validator passed. Detail: { formData, values, submitter, waitUntil(promise) }. The page does not navigate. |
invalid-submit | CustomEvent<InvalidSubmitEventDetail> | A submit attempt found errors. Detail: { errors: { name, message, control }[] }. |
dirty-change | CustomEvent<DirtyChangeEventDetail> | The values started or stopped differing from the pristine state. Detail: { dirty }. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
summary | The error summary. |
summary-heading | The summary heading. |
summary-link | Each entry of the summary. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-form--display | display | grid | block leaves the form's own layout alone. |
--c2-form--columns | grid-template-columns | minmax(0, 1fr) | Columns of the form's grid. |
--c2-form--gap | pixel | 18px | Space between the form's rows. |
--c2-form--column-gap | pixel | 16px | Space between the form's columns. |
--c2-form__summary--margin-bottom | pixel | 18px | |
--c2-form__summary--padding | padding | 14px 16px | |
--c2-form__summary--border | border | 1px solid #dc2626 | |
--c2-form__summary--border-radius | border-radius | 8px | |
--c2-form__summary--background | color | #ffffff | |
--c2-form__summary--color | color | #18181b | Text of the summary entries. |
--c2-form__summary__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-form__summary-heading--color | color | #dc2626 | |
--c2-form__summary-heading--font-size | font-size | 14px | |
--c2-form__summary-heading--font-weight | font-weight | 600 | |
--c2-form__summary-link--color | color | #dc2626 | |
--c2-form__summary-link--font-size | font-size | 14px | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under form, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
summaryHeading | There are {0} problems with this form | {0} count |