NG Kit

Validation

Validates the autocomplete like any other Material form field. Bind it with formControlName, set invalid from the control (here once it is touched) to turn the label and underline red, and pass helperText — shown as a mat-hint while valid and as a mat-error, linked via aria-describedby, while invalid. required adds the label asterisk. Leave a field and press Submit to compare it with the plain mat-select beside it.

Usage

Import AutocompleteComponent and configure it with the inputs below. The full runnable source is on the Examples tab.

html
<autocomplete
  formControlName="film"
  [options]="films"
  [required]="true"
  [invalid]="film.invalid && film.touched"
  [helperText]="film.invalid && film.touched ? 'Movie is required' : 'Start typing to search'"
  label="Movie" />

API

This example demonstrates the inputs below. See the Autocomplete introduction for the complete API — every input, output, content template and filter helper.

Inputs

NameTypeDefaultDescription
requiredbooleanfalseMarks the control required (label asterisk + aria-required).
invalidbooleanfalsePuts the field in its error state (red label/underline, aria-invalid) and shows helperText as a mat-error.
helperTextstring | nullnullText under the field: a mat-hint normally, a mat-error while invalid (MUI helperText).