# Forms Support

You can use the TextBox in [Template-driven](https://www.telerik.com/kendo-angular-ui/components/inputs/textbox/forms#template-driven-forms) and [Reactive](https://www.telerik.com/kendo-angular-ui/components/inputs/textbox/forms#reactive-forms) forms. The TextBox implements [`ControlValueAccessor`](https://angular.dev/api/forms/ControlValueAccessor), which means it integrates natively with Angular's form APIs without any extra configuration.

## Template-Driven Forms

Template-driven forms use Angular's [`NgModel`](https://angular.dev/api/core/NgModule#) directive to bind the TextBox value to a component property. To declare the TextBox as a form field, add the `name` attribute and bind the value through `[(ngModel)]`.

Angular's built-in validators, such as [`required`](https://angular.dev/api/forms/RequiredValidator), [`minlength`](https://angular.dev/api/forms/MinLengthValidator), and [`maxlength`](https://angular.dev/api/forms/MaxLengthValidator), work as attributes directly on the `kendo-textbox` element. Angular reads these attributes and attaches the corresponding validators to the bound `NgModel` control.

The following example demonstrates how to use the TextBox in a template-driven form with `required` validation.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/inputs/textbox/template-driven/source.txt)

The TextBox reflects the Angular form control state through CSS classes (`ng-valid`, `ng-invalid`, `ng-touched`, `ng-dirty`). To display visual icons alongside the validation state, use the [`showSuccessIcon`](https://www.telerik.com/kendo-angular-ui/components/inputs/api/textboxcomponent#showsuccessicon) and [`showErrorIcon`](https://www.telerik.com/kendo-angular-ui/components/inputs/api/textboxcomponent#showerroricon) properties. Setting either property to `'initial'` shows the icon after the field has been touched and the validation state changes.

## Reactive Forms

[Reactive forms](https://angular.dev/guide/forms/reactive-forms) are model-driven and defined in the component class through `FormControl` and `FormGroup`. Bind a `FormControl` to the TextBox by using the `formControlName` directive on `kendo-textbox`.

The `FormGroup` provides a way to render reactive forms. For more details, refer to the [Angular Documentation](https://angular.dev/guide/forms/dynamic-forms#bootstrap).

The following example demonstrates how to use the TextBox in a reactive form.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/inputs/textbox/reactive/source.txt)

Pass built-in Angular validators from `Validators` as the second argument to `FormControl`. Common options include `Validators.required`, `Validators.minLength()`, and `Validators.email`. You can combine multiple validators in an array:

```typescript
import { FormControl, FormGroup, Validators } from '@angular/forms';

this.form = new FormGroup({
    name: new FormControl('', [Validators.required, Validators.minLength(3)]),
    email: new FormControl('', [Validators.required, Validators.email])
});
```

## Validation and Error Handling

To display contextual error messages alongside the TextBox, wrap it in a [Kendo FormField](https://www.telerik.com/kendo-angular-ui/components/inputs/form/formfield). Use `kendo-formerror` elements for error messages and `kendo-formhint` for persistent helper text. For more information, refer to the [FormField Hints and Errors](https://www.telerik.com/kendo-angular-ui/components/inputs/form/formfield/hints-errors) article.

The FormField automatically shows `kendo-formerror` messages when the bound control is both invalid and touched (the default `showErrors="initial"` behavior). To always show error messages regardless of touch state, set `showErrors="always"` on the `kendo-formfield`.

The following example demonstrates a reactive form with field-level error messages for multiple validators.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/inputs/textbox/forms-validation/source.txt)

> note Server-side validation remains essential for application security and data integrity. Client-side validation improves user experience but must be complemented by server-side checks.

## Managing the TextBox Disabled State in Reactive Forms

To disable the TextBox component when working with reactive forms and Angular 15 or later, use the FormControl's [`disabled` property/option](https://angular.dev/api/forms/AbstractControl#disabled) or [`disable()` method](https://angular.io/api/forms/AbstractControl#disable).

> Angular 15 introduces a [breaking change](https://github.com/angular/angular/pull/47576) affecting the synchronization of [`setDisabledState`](https://angular.dev/api/forms/ControlValueAccessor#setDisabledState) with the model-DOM. This impacts components using the [`disabled` attribute](https://angular.dev/api/forms/AbstractControl#disabled). As a result, the [`disabled`](https://www.telerik.com/kendo-angular-ui/components/inputs/api/textboxcomponent#disabled) property of the Kendo UI for Angular components used prior to Angular 15 is no longer working in reactive forms.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/inputs/textbox/reactive-forms-disabled/source.txt)

## Suggested Links

* [Validation Icons of the TextBox](https://www.telerik.com/kendo-angular-ui/components/inputs/textbox/validation-icons)
* [Password Type of the TextBox](https://www.telerik.com/kendo-angular-ui/components/inputs/textbox/password)
* [Adornments of the TextBox](https://www.telerik.com/kendo-angular-ui/components/inputs/textbox/adornments)
* [API Reference of the TextBox](https://www.telerik.com/kendo-angular-ui/components/inputs/api/textboxcomponent)
