Skip to content

ErrorText

ErrorText<T>(props): ReactElement

Defined in: ErrorText.tsx:37

Render the error messages of form fields

ErrorText.Props<T>

ReactElement

  • Shows what form.getErrors() returns for each field: its errors once the field reports them
  • Renders a <span data-error-text> holding a <span> for each field with errors, which holds a <span> per message, and nothing while there are none
  • Gives the <span> of each field the id from errorTextId, which the standard bindings point the field's form control at with aria-describedby while the errors are reported. Show each field in one ErrorText, so that the id stays unique on the page.
  • Other props, such as className and id, go to the outer <span>
  • Re-renders as the errors change, so the component that renders it need not be an observer
<input {...form.bindInput("city", { ... })} />
<ErrorText form={form} fields={["city"]} />
// One text for a row of fields
<ErrorText form={form} fields={["city", "region", "postalCode"]} className="error" />

Props<T> = Omit<React.HTMLAttributes<HTMLSpanElement>, "children"> & object

Defined in: ErrorText.tsx:7

fields: readonly FormField.Name<T>[]

Fields to show the errors of

form: Form<T>

Form the fields belong to