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

Preventing submit click if Date entered is invalid.

6 Answers 604 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Shubh
Top achievements
Rank 1
Shubh asked on 26 May 2014, 12:25 PM
How do we prevent submit button click, if user has selected invalid date.

Currently, I am able to display the error message. But even if the error message is there and user clicks on Submit/Save  I am still able to submit form with invalid date.

While searching in Google, I found one suggestion to achieve this is adding RequiredFieldValidator on page. But this would turn make that field mandatory, which I cannot do.

Thanks.

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 May 2014, 12:56 PM
Hi Shubh,

One suggestion is that based on the condition you can enable/disable the Save Button. Please have a look into the JavaScript which checks the condition like if the selected date is greater than 15 then it will enable the button otherwise it will disable the button.

JavaScript:
function ValidateDate(sender, args) {
    var button = $find("<%=RadButton1.ClientID %>");
    var selectDate = new Date(args.get_newDate());
    if (selectDate.getDate() > 15)
        button.set_enabled(true);
    else
        button.set_enabled(false);
}

Please let me know if you have any concern.
Thanks ,
Princy.
0
Shubh
Top achievements
Rank 1
answered on 27 May 2014, 06:11 AM
Hey Princy,

Thanks for you suggestion. Will implement it.

Before that, is Calendar control build like that? In case of invalid date also it will allow the page to submit?

If Yes, then how do I maintain the error message?

Thanks.
0
Princy
Top achievements
Rank 2
answered on 27 May 2014, 06:41 AM
Hi Shubh,

The OnError client-side event is fired when one tries to set invalid value for the DateInput. You can handle the InvalidDate in OnError event and prevent the Button Click and validate the form. 

Thanks,
Princy.
0
Shubh
Top achievements
Rank 1
answered on 27 May 2014, 07:09 AM
Let me try that. Thanks.
0
Shubh
Top achievements
Rank 1
answered on 27 May 2014, 09:59 AM
I have my code as below:

<telerik:RadDatePicker ID="rdpDob" runat="server" AutoPostBack="true"   DateInput-EmptyMessage="MaxDate" MinDate="01/01/1000"MaxDate="01/01/3000">

I am validating in my Server Side. Now, when I enter invalid data in my date field, I don't get the entered invalid values. 

rdpDob.SelectedDate

This return's  null.

Any idea what I am missing?

Thanks,
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 May 2014, 03:19 AM
Hi Shubh,

The current implementation of RadDatePicker/RadDateTimePicker there is no way of posting back invalid Date to server. This is due to the reason that picker control tries to parse value posted from client to DateTime and this might break the control. If the value is not valid DateTime on postback it will be cleared. On server side you can actually access the invalid value via InvalidTextBoxValue property of the picker as follows.

C#:
string invalidDate=RadDatePicker1.DateInput.InvalidTextBoxValue;

Thanks,
Princy.
Tags
Calendar
Asked by
Shubh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shubh
Top achievements
Rank 1
Share this question
or