New to Kendo UI for AngularStart a free 30-day trial

FormField Hints and Errors

The FormField component allows you to display hints and error messages for form controls. It is designed to enhance the user experience by providing contextual information about the form fields.

To use the FormField component for displaying hints and errors, you need to include the HintComponent and FormErrorComponent components inside the FormField component.

html
<kendo-formfield>
  <kendo-label [for]="name" text="Name"></kendo-label>
  <kendo-textbox #name formControlName="name"></kendo-textbox>
  <kendo-formhint>Enter your full name</kendo-formhint>
  <kendo-formerror>Invalid name</kendo-formerror>
</kendo-formfield>

The following example demonstrates the FormField component with hints and errors in action.

Change Theme
Theme
Loading ...

Controlling the Visibility

By default, the errors are hidden and will be displayed when the form control is invalid after user interaction. If provided, the hints will be initially visible and will hide if an error occurs. You can control the visibility of the hint and error messages by setting the showHints and showErrors properties of the FormField component.

The available showHints values are:

  • initial—The hint messages are displayed when the state of the form-bound component is valid or untouched, and pristine.
  • always—The hint messages are always displayed, leaving the control of their content visibility to the developer.

The available showErrors values are:

  • initial—The error messages are displayed when the state of the form-bound component is invalid and touched, or dirty.
  • always—The error messages are always displayed, leaving the control of their content visibility to the developer.

The following example demonstrates the visibility of the hint and error messages.

html
<kendo-formfield showHints="always" showErrors="initial">
  <kendo-label [for]="name" text="Name"></kendo-label>
  <kendo-textbox #name formControlName="name"></kendo-textbox>
  <kendo-formhint>Enter your full name</kendo-formhint>
  <kendo-formerror>Invalid name</kendo-formerror>
</kendo-formfield>

Changing the Alignment

The messages can be displayed at the start or end of the input and can be controlled by setting the align property of the HintComponent and ErrorComponent.

html
<kendo-formhint align="start">Your username</kendo-formhint>
<kendo-formerror align="end">Error: Username is required</kendo-formerror>

The following example aligns the error message to the end of the input and the hint message to the start of the input.

Change Theme
Theme
Loading ...