How to show user message when used types date that is less than MinDate

4 posts, 0 answers
  1. John
    John avatar
    31 posts
    Member since:
    May 2014

    Posted 21 Jul 2015 Link to this post

    Hello,

    At the moment I am setting the MinDate and MaxDate properties on a RadDatePicker ​in the code behind. This works well with regard to the calendar because it is not possible to select dates outside of the range with the mouse.

    However, the user may still enter dates by typing. At the moment, the default behaviour isn't great. What I would is to present the user with a meaningful message if they type a date outside of the range, preferably when the control loses focus.

    I am wondering what the best way to do this is? Do I need to implement something based on <asp:CompareValidator/> or is there a better way?

    Thanks in advance,

    John.

  2. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 24 Jul 2015 Link to this post

    Hello John,

    The most straightforward approach would be to disable the input typing:
    <DateInput runat="server" ReadOnly="true"></DateInput>

    The alternative way is to use the OnError client-side event handler:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/input/client-side-programming/events/onerror

    For your convenience, I have created a sample implementation:
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server" MinDate="2015/7/7">
        <DateInput runat="server">
            <ClientEvents OnError="pickerError" />
        </DateInput>
    </telerik:RadDatePicker>
    JavaScript:
    function pickerError(sender, args) {
        var reason = args.get_reason();
        if (reason == 2) {
            alert("Please choose within the range");
        }
    }

    Hope this helps. Please give it a try and let me know if it works for you.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John
    John avatar
    31 posts
    Member since:
    May 2014

    Posted 03 Sep 2015 in reply to Eyup Link to this post

    Thank you for your reply and apologies for the delay. I had actually moved on to another issue in the meantime. I will bear this solution in mind however, should we need to do something similar again. 
  5. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 08 Sep 2015 Link to this post

    Hi John,

    Please take your time to examine the suggested approach.
    Feel free to turn to us if new questions arise.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top