Hi,
When a date such as 30/02/1975 is manually entered into the text box of a RadDatePicker control, it is automatically changed to 28/02/1975 without giving any warning or error.
Our client wishes for the behaviour under such circumstances to be the same as if an invalid date is entered - i.e.if you enter 40/02/1975 the text box border is set to red and a warning icon appears.
Is it possible to alter the RadDatePicker behaviour so that it will treat dates such as 30/02/1975 in the same way as invalid dates (i.e. show the warning icon and red border)?
Regards,
Dave
When a date such as 30/02/1975 is manually entered into the text box of a RadDatePicker control, it is automatically changed to 28/02/1975 without giving any warning or error.
Our client wishes for the behaviour under such circumstances to be the same as if an invalid date is entered - i.e.if you enter 40/02/1975 the text box border is set to red and a warning icon appears.
Is it possible to alter the RadDatePicker behaviour so that it will treat dates such as 30/02/1975 in the same way as invalid dates (i.e. show the warning icon and red border)?
Regards,
Dave
9 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 23 Nov 2011, 04:25 AM
Hello,
You can take a look into the following demo which illustrate the same.
Calendar / Validation
Thanks,
Princy.
You can take a look into the following demo which illustrate the same.
Calendar / Validation
Thanks,
Princy.
0

DM
Top achievements
Rank 1
answered on 23 Nov 2011, 10:53 AM
Hi,
thank you for the reply. I took a look at the example you posted, but this illustrates using ASP.NET validators to validate the dates entered, which is not quite what I was looking for. I will try to explain more clearly:
Case 1 - For dates that are typed into the RadDatePicker text box directly and that have a 'day' component that is potentially valid for some months (i.e. 1-31), but is for a month for which is not valid (i.e. 30 in February), the RadDatePicker automatically changes the entered date to the last valid day in the month (e.g. 28 for February) without giving any error warning. An example would be 30/02/1975. This is problematic because people could mistakenly enter 30/02/1975 instead of 03/02/1975 and not realize their mistake as the control does not indicate an error.
Case 2 - If you enter a day that is definitely invalid in any month (i.e. 40), the RadDatePicker leaves the date in an invalid state and indicates an error. An example would be 40/02/1975. The control clearly indicates a problem in this case that the user can then correct.
The behaviour between these 2 cases is different, and the client is asking for the behaviour in case 1 to be identical to that in case 2 - i.e. The RadDatePicker should signal an invalid date by putting a red border on the text box and displaying the warning icon when a date such as 30/02/1975 is entered directly into the text box.
Is this possible to do?
Regards,
Dave
thank you for the reply. I took a look at the example you posted, but this illustrates using ASP.NET validators to validate the dates entered, which is not quite what I was looking for. I will try to explain more clearly:
Case 1 - For dates that are typed into the RadDatePicker text box directly and that have a 'day' component that is potentially valid for some months (i.e. 1-31), but is for a month for which is not valid (i.e. 30 in February), the RadDatePicker automatically changes the entered date to the last valid day in the month (e.g. 28 for February) without giving any error warning. An example would be 30/02/1975. This is problematic because people could mistakenly enter 30/02/1975 instead of 03/02/1975 and not realize their mistake as the control does not indicate an error.
Case 2 - If you enter a day that is definitely invalid in any month (i.e. 40), the RadDatePicker leaves the date in an invalid state and indicates an error. An example would be 40/02/1975. The control clearly indicates a problem in this case that the user can then correct.
The behaviour between these 2 cases is different, and the client is asking for the behaviour in case 1 to be identical to that in case 2 - i.e. The RadDatePicker should signal an invalid date by putting a red border on the text box and displaying the warning icon when a date such as 30/02/1975 is entered directly into the text box.
Is this possible to do?
Regards,
Dave
0
Hello Dave,
The DateInput is made to try parsing and auto correct the values. The idea is not to limit the user entering dates in different formats.
If you need to do more strict parsing you could handle the OnValueChanging event and do further checking manually.
Regards,
Vasil
the Telerik team
The DateInput is made to try parsing and auto correct the values. The idea is not to limit the user entering dates in different formats.
If you need to do more strict parsing you could handle the OnValueChanging event and do further checking manually.
Regards,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0

DM
Top achievements
Rank 1
answered on 25 Nov 2011, 12:43 PM
Hi Vasil,
thank you for your reply. I'm still struggling with this - I have followed your advice and implemented the OnValueChanging event, and am therefore able to determine the circumstances under which the datepicker will change the entered date i.e. 31st feb to 28th feb.
So I get to the end of my javascript function and I want the datepicker to keep the invalid date I entered (e.g. 31/02/1975) and show the error in the same way as completely invalid date. At this point I am still at a loss. I do not see how I can force the datepicker to do this - i.e. validate the entered date without changing it, and highlight the textbox in red as in other validation failures.
The client has stated that it is essential that error reporting behaviour is uniform across all invalid dates and that dates are not changed on the fly.
Using set_cancel(true) from OnValueChanging removes the entered date completely, and if I don't cancel it, the date is changed to 28/02/1975 by the datepicker.
I then tried implementing the OnDateChanged event as well, storing the invalid date in a global variable and trying to reapply it in OnDateChanged but this did not work. I'm guessing by this point it is too late.
Is what I am trying to do possible? Can the datepicker's default behaviour of changing dates such as 31st Feb be stopped?
Regards,
Dave
thank you for your reply. I'm still struggling with this - I have followed your advice and implemented the OnValueChanging event, and am therefore able to determine the circumstances under which the datepicker will change the entered date i.e. 31st feb to 28th feb.
So I get to the end of my javascript function and I want the datepicker to keep the invalid date I entered (e.g. 31/02/1975) and show the error in the same way as completely invalid date. At this point I am still at a loss. I do not see how I can force the datepicker to do this - i.e. validate the entered date without changing it, and highlight the textbox in red as in other validation failures.
The client has stated that it is essential that error reporting behaviour is uniform across all invalid dates and that dates are not changed on the fly.
Using set_cancel(true) from OnValueChanging removes the entered date completely, and if I don't cancel it, the date is changed to 28/02/1975 by the datepicker.
I then tried implementing the OnDateChanged event as well, storing the invalid date in a global variable and trying to reapply it in OnDateChanged but this did not work. I'm guessing by this point it is too late.
Is what I am trying to do possible? Can the datepicker's default behaviour of changing dates such as 31st Feb be stopped?
Regards,
Dave
0

DM
Top achievements
Rank 1
answered on 25 Nov 2011, 12:50 PM
Hi Vasil,
I solved the problem - I'm not sure why it works but it does. I figured in the meantime, as a temporary placeholder solution, I would set the date to a completely invalid date such as 99/02/1975 so the datepicker would pick that up and highlight it in red.
It turns out that it does - but it doesn't change the date, so it stays at the original entered date with error highlighting in place. Perfect!
Thanks for your time.
Regards,
Dave
I solved the problem - I'm not sure why it works but it does. I figured in the meantime, as a temporary placeholder solution, I would set the date to a completely invalid date such as 99/02/1975 so the datepicker would pick that up and highlight it in red.
It turns out that it does - but it doesn't change the date, so it stays at the original entered date with error highlighting in place. Perfect!
Thanks for your time.
Regards,
Dave
0
Hi Dave,
You could override the parseDate function that is used for parsing the dates. In the code below I highlighted the changes that you could use to see if the parsed date is the same as entered by the user.
All the best,
Vasil
the Telerik team
You could override the parseDate function that is used for parsing the dates. In the code below I highlighted the changes that you could use to see if the parsed date is the same as entered by the user.
<
script
type
=
"text/javascript"
>
Telerik.Web.UI.RadDateInput.prototype.parseDate = function (value, baseDate)
{
try
{
var lexer = new Telerik.Web.UI.DateParsing.DateTimeLexer(this.get_dateFormatInfo());
var tokens = lexer.GetTokens(value);
var parser = new Telerik.Web.UI.DateParsing.DateTimeParser(this.get_dateFormatInfo().TimeInputOnly);
var entry = parser.Parse(tokens);
baseDate = this._getParsingBaseDate(baseDate);
var date = entry.Evaluate(baseDate, this.get_dateFormatInfo());
if (date.getDate() != entry.First || date.getMonth() + 1 != entry.Second || date.getFullYear() != entry.Third)
{
return null;
}
return date;
}
catch (parseError)
{
if (parseError.isDateParseException)
{
return null;
}
else
{
throw parseError;
}
}
}
</
script
>
<
div
>
<
telerik:RadDateInput
ID
=
"RadDateInput1"
runat
=
"server"
DateFormat
=
"dd/MM/yyyy"
MinDate
=
"1900.1.1"
>
</
telerik:RadDateInput
>
</
div
>
All the best,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0

DM
Top achievements
Rank 1
answered on 25 Nov 2011, 03:02 PM
Hi Vasil,
that worked perfectly, and is much more elegant than my solution.
Thank you very much for your help, it's much appreciated!
Regards,
Dave
that worked perfectly, and is much more elegant than my solution.
Thank you very much for your help, it's much appreciated!
Regards,
Dave
0

DM
Top achievements
Rank 1
answered on 28 Nov 2011, 10:45 AM
Hi, I'm back again......
The code you supplied works perfectly for raddatetimepickers, but on pages where there are radtimepickers as well, it unfortunately stops the radtimepicker from accepting any time. Typing a time manually gives the usual error highlighting, and trying to select a time from the menu doesn't work at all - the menu stays open and the time is not populated.
EDIT:
I figured out a solution, never mind - I check the entry type and only perform custom validation when it is DATETRIPLET.
Regards,
Dave
The code you supplied works perfectly for raddatetimepickers, but on pages where there are radtimepickers as well, it unfortunately stops the radtimepicker from accepting any time. Typing a time manually gives the usual error highlighting, and trying to select a time from the menu doesn't work at all - the menu stays open and the time is not populated.
EDIT:
I figured out a solution, never mind - I check the entry type and only perform custom validation when it is DATETRIPLET.
Regards,
Dave
0
Hello Dm,
Thank you for sharing the solution with the community since it could help someone else.
Indeed the best solution seems to be additional check of the "Type" of the "entry" for "DATETRIPLET"
Greetings,
Vasil
the Telerik team
Thank you for sharing the solution with the community since it could help someone else.
Indeed the best solution seems to be additional check of the "Type" of the "entry" for "DATETRIPLET"
Greetings,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now