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

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

3 Answers 80 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 21 Jul 2015, 11:27 AM

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.

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Jul 2015, 09:02 AM
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
0
John
Top achievements
Rank 1
answered on 03 Sep 2015, 02:29 PM
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. 
0
Eyup
Telerik team
answered on 08 Sep 2015, 11:13 AM
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
Tags
DatePicker
Asked by
John
Top achievements
Rank 1
Answers by
Eyup
Telerik team
John
Top achievements
Rank 1
Share this question
or