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

A way to stop automatic changing of dates if out of range?

1 Answer 58 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 17 Nov 2020, 03:20 AM
We have our days in dd-MM-yyyy format and it's mostly working fine, we have a few fringe cases though where it could have the user add the wrong date in by accident and not notice when they type them.

For example 31-04 reverts the date to 01-04, is it possible to still have the formatting in place but allow the check to be done by a regex pattern? or can we distinguish which way the autocorrect goes, for example above we would want it to autochange to 30-04?



@(Html.Kendo().DatePicker().Name("txt_" + Model.QuestionID.ToString()).Value(Model.AnswerModel.AnswerText).Format("dd-MM-yyyy").DateInput()
    .Popup(p =>
    {
        p.Origin("bottom right");
        p.Position("top right");
    })
    .Deferred().HtmlAttributes(new
    {
        style = "width:100%",
        @id = "txt_" + Model.QuestionID.ToString(),
        pattern = pattern
    }))

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 18 Nov 2020, 05:10 PM

Hello Scott,

I am afraid that with the current API of the DatePicker it is not possible to create custom rules to validate and parse dates. The DatePciker is designed to do the parsing automatically when an invalid date is entered. The parsing is approved following the best UX practices.

Another possible approach I can recommend here is to display a validation tooltip to the user for a wrong date. This approach utilizes the Kendo UI Validator. In this way, you can provide an error message to end users which prompts them to do the right actions for them to resolve the issue. For a runnable demo please refer to the following link:

Let me know if you have any questions.

Regards,
Nikolay
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/.

Tags
Date/Time Pickers
Asked by
n/a
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or