4 Answers, 1 is accepted
0
Shaindy
Top achievements
Rank 1
answered on 17 Mar 2016, 10:45 AM
BTW, regarding my previous post, the bound data is not a null-able datatype.
Also, Is there a reason why the validation for the datepicker in general doesn't work like the validation for other controls where the user cannot lose focus until they select valid data, as opposed to clearing the field?
0
Hi Shaindy,
By design the whenever the input cannot be parsed to valid value, the SelectedDate property are set to null. However whenever the SelectedDate is bound to non nullable DateTime - it is not possible the property to be set to null that is why it is not changed.
What you can do in this scenario would be to hook to the ParseDateTimeValue event and check in the arguments whether the parsing is successful. If not you could simply revert the selected value to the previous one:
Hope this helps.
Regards,
Kalin
Telerik
By design the whenever the input cannot be parsed to valid value, the SelectedDate property are set to null. However whenever the SelectedDate is bound to non nullable DateTime - it is not possible the property to be set to null that is why it is not changed.
What you can do in this scenario would be to hook to the ParseDateTimeValue event and check in the arguments whether the parsing is successful. If not you could simply revert the selected value to the previous one:
private
void
Picker_ParseDateTimeValue(
object
sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
{
if
(!args.IsParsingSuccessful)
{
args.IsParsingSuccessful =
true
;
args.Result = args.PreviousValue;
}
}
Hope this helps.
Regards,
Kalin
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Shaindy
Top achievements
Rank 1
answered on 22 Mar 2016, 06:30 AM
Thanks for explaining how to make the UI reflect the fact that the value hasn't changed.
Can you please address my second question of how to change the behavior so that instead of resetting the date, the user is not allowed to lose focus until he fixes the data?
0
Hi Shaindy,
One approach to make sure that there would always be a valid date selected is to implement a Data Validation of bound property. For more details you can check the following example from our online Silverlight demos (the approach is the same for WPF):
http://demos.telerik.com/silverlight/#DateTimePicker/Validation
Hope this will help you to achieve the desired.
Regards,
Kalin
Telerik
One approach to make sure that there would always be a valid date selected is to implement a Data Validation of bound property. For more details you can check the following example from our online Silverlight demos (the approach is the same for WPF):
http://demos.telerik.com/silverlight/#DateTimePicker/Validation
Hope this will help you to achieve the desired.
Regards,
Kalin
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.