How to create validation for DateTimePicker to check that the StartDate control is not later than the EndDate control ?

1 Answer 107 Views
DateTimePicker
Matt
Top achievements
Rank 1
Iron
Iron
Matt asked on 31 Oct 2022, 04:46 PM

I have been trying to create something in the style below. But the event never seems to fire when I select a date. Help  ? 

 

 

  //  validators: [this.sessionStartEndLogic()],
               

//  updateOn: 'change'

 

 

1 Answer, 1 is accepted

Sort by
0
Martin Bechev
Telerik team
answered on 03 Nov 2022, 01:57 PM

Hi Matt,

The DateTimePicker component doesn't have a start and end date. Rather it is a component for selecting a single date and time only.

In case the DateTimePicker is used for selecting a start and end date, the most straightforward approach to verify that the selected ranges are correct is to utilize the min and max properties of the components.

https://www.telerik.com/kendo-angular-ui/components/dateinputs/datetimepicker/date-time-limits/#toc-calendar-and-timepicker-ranges

You can update them dynamically on valueChange event hander, as the following example demonstrates:

https://stackblitz.com/edit/angular-zzhelq

Such an approach will avoid selecting dates that will otherwise generate an invalid duration. 

Please let me know if this fits the project, if not please provide some more details about the desired end goal and how the controls are expected to behave. Thank you in advance.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Matt
Top achievements
Rank 1
Iron
Iron
commented on 04 Nov 2022, 01:37 PM

that makes sense.. I was just thinking of them as controls I need to validate but really I can just prevent them from ever selecting an invalid date.. ill go try now
Tags
DateTimePicker
Asked by
Matt
Top achievements
Rank 1
Iron
Iron
Answers by
Martin Bechev
Telerik team
Share this question
or