This is a migrated thread and some comments may be shown as answers.

DateRangePicker Validation

1 Answer 887 Views
DateRangePicker
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 13 Feb 2020, 08:38 PM

Hi,

I tried to use Required DataAnnotation on Start and End properties of my viewmodel to validate DateRangePicker.

But seems like it is not working by default.

Any suggestion on validating DateRangePicker control?

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 17 Feb 2020, 03:09 PM

Hello Hugo,

It is possible to add a min and max settings and when the input is blurred, it will set the closest date to either min or max if the user tried to enter an invalid date:

https://docs.telerik.com/kendo-ui/api/javascript/ui/daterangepicker/configuration/max

https://docs.telerik.com/kendo-ui/api/javascript/ui/daterangepicker/configuration/min

As for the required validation, currently, it is a little complex because the inputs have no name but still could be achieved. Here are the steps:

- add names to the inputs of the Kendo UI DateRangePicker and validation message attributes
- add the validateOnBlur: false setting to the Kendo UI Validator because the ranges are not yet updated on blur and neither is the input
- add a change event handler to the DateRangePicket and call the validator validate() method

I have prepared a small Dojo demo demonstrating the above:

Let me know if you have any questions.

Regards,
Nikolay
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DateRangePicker
Asked by
n/a
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or