Forms Support

You can use the DateTimePicker in Template-driven and Reactive forms.

Template-Driven Forms

The template-driven forms enable you to bind the DateTimePicker to the model by using the ngModel directive.

The following example demonstrates how to use the DateTimePicker in template-driven forms.

@Component({
    selector: 'my-app',
    template: `
        <form>
            <div class="example-config">
                <strong>Value: {{checkIn | json}}</strong> |
                <strong>Valid: {{model.valid}}</strong> |
                <strong>Touched: {{model.touched}}</strong> |
                <strong>Pristine: {{model.pristine}}</strong> |
                <strong>Errors: {{model.errors | json}}</strong>
            </div>
            <label>
                <div>
                    Select check-in date and time:
                </div>
                <kendo-datetimepicker
                    #model="ngModel"
                    required
                    name="check-in"
                    [min]="min"
                    [(ngModel)]="checkIn"
                >
                </kendo-datetimepicker>
                <button type="button" class="k-button" (click)="model.reset()">Reset</button>
            </label>
        </form>
    `
})
class AppComponent implements OnInit {
    public checkIn: Date = null;
    public min: Date;

    public ngOnInit(): void {
        const currentDay = new Date();
        const nextDayNoon = new Date(currentDay.getFullYear(), currentDay.getMonth(), currentDay.getDate() + 1, 12);

        this.min = nextDayNoon;
    }
}

Reactive Forms

The FormGroup decorator provides a way to render reactive forms. For more details, refer to the Angular documentation.

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

import {
       FormsModule,
       ReactiveFormsModule,
       FormGroup,
       FormControl
   } from '@angular/forms';

   @Component({
       selector: 'my-app',
       template: `
           <form [formGroup]="form">
               <div class="example-config">
                   <strong>Value: {{form?.controls.checkIn.value | json}}</strong> |
                   <strong>Valid: {{form?.controls.checkIn.valid}}</strong> |
                   <strong>Touched: {{form?.controls.checkIn.touched}}</strong> |
                   <strong>Pristine: {{form?.controls.checkIn.pristine}}</strong> |
                   <strong>Errors: {{form?.controls.checkIn.errors | json}}</strong>
               </div>
               <label>
                   <div>
                       Select check-in date and time:
                   </div>
                   <kendo-datetimepicker
                       required
                       formControlName="checkIn"
                       [min]="min"
                   >
                   </kendo-datetimepicker>
                   <button type="button" class="k-button" (click)="form.reset()">Reset</button>
               </label>
           </form>
       `
   })
   class AppComponent {
       public min: Date;

       public form: FormGroup = new FormGroup({
           checkIn: new FormControl(null)
       });

       public ngOnInit(): void {
           const currentDay = new Date();
           const nextDayNoon = new Date(currentDay.getFullYear(), currentDay.getMonth(), currentDay.getDate() + 1, 12);

           this.min = nextDayNoon;
       }
   }

In this article