Skip to main content
cngx-src documentation

CngxFormErrors

ComponentPrimaryOnPushNo encapsulationv0.1.0WCAG AA

projects/forms/field/form-errors.component.ts

Import#

import { CngxFormErrors } from '@cngx/forms/field'

Description#

Form-level error summary - lists all validation errors across all fields.

Place outside (or at the top/bottom of) the form. Each error is a focusable link that jumps to the invalid field via focusBoundControl().

Only visible when showErrors() is true (controlled by the consumer, typically set after a failed submit).

This implements the WCAG 3.3.1 pattern: "If an input error is detected, the item that is in error is identified and the error is described to the user in text."

<cngx-form-errors [fields]="[emailField, passwordField]" [show]="showFormErrors()">
</cngx-form-errors>

Custom template

<cngx-form-errors [fields]="[emailField, passwordField]" [show]="submitted()">
  <ng-template let-errors="errors" let-count="count">
    <h3>{{ count }} errors found</h3>
    @for (err of errors; track err.fieldName) {
      <a (click)="err.focus()" href="javascript:void(0)">
        {{ err.fieldName }}: {{ err.message }}
      </a>
    }
  </ng-template>
</cngx-form-errors>

https://cngxjs.github.io/cngx/examples/#/forms/field/form-errors/basic https://cngxjs.github.io/cngx/examples/#/forms/field/form-errors/show-on-submit https://cngxjs.github.io/cngx/examples/#/forms/field/form-errors/custom-summary-template https://cngxjs.github.io/cngx/examples/#/forms/field/form-errors/server-error-injection

Metadata#

Host#

Relationships

Index#

Inputs#

input()Required

The field accessors to summarize errors for.

show#
input()

Whether to show the error summary (typically set after a failed submit).

default false

Instance Properties#

customTpl#unknown
ProtectedReadonly

Optional custom template.

contentChild<TemplateRef<CngxFormErrorsSummaryContext>>(TemplateRef)

HostBindings#

BindingExpression
[attr.role]show() && errorItems().length > 0 ? "alert" : null
[attr.aria-live]"polite"

Default visuals for CngxFieldErrors - bulleted error list rendered under a form field. The host carries .cngx-form-errors and stays display: contents; the inner .cngx-form-errors__list holds the list typography and color.

Slots

  • .cngx-form-errors__list - the <ul> element, font-size + danger color
  • .cngx-form-errors__list a - inline anchors inherit color and carry an underline that drops on :hover / :focus-visible so the interaction state reads independently of the resting decoration

Inheritance

Tokens delegate to the foundation so a brand override propagates without per-component theming:

  • --cngx-form-errors-font-size -> --cngx-font-size-sm
  • --cngx-form-errors-color -> --cngx-field-error-color -> --cngx-color-danger

A :root delegating rule pins --cngx-form-errors-color to --cngx-color-danger so a dark-mode swap on the foundation token cascades through.

Index#

Typography

--cngx-form-errors-font-size#*
Default value 0.875rem

Font-size of the error list. Falls back through --cngx-font-size-sm. syntax: '*' allows rem.

Surface

--cngx-form-errors-color#<color>
Default value oklch(0.55 0.21 27)

Text color of the error list. Falls back through --cngx-field-error-color and then --cngx-color-danger.

See: [[--cngx-color-danger]]