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

2 posts, 0 answers
  1. Scott Walsh
    Scott Walsh avatar
    1 posts
    Member since:
    Feb 2019

    Posted 16 Nov 2020 Link to this post

    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
        }))
  2. Nikolay
    Admin
    Nikolay  avatar
    301 posts

    Posted 18 Nov 2020 Link to this post

    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/.

Back to Top