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

Problem with the new IsInputRestrictedToSelectableDates property in the DatePicker

4 Answers 61 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Shaindy
Top achievements
Rank 1
Shaindy asked on 17 Mar 2016, 08:48 AM

If the user changes the input box to an invalid date and then loses focus, the input box is cleared.  However, the bound data still has the original valid date.

I need the input box to reflect the data it is bound to.

4 Answers, 1 is accepted

Sort by
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
Kalin
Telerik team
answered on 21 Mar 2016, 11:13 AM
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:

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
Kalin
Telerik team
answered on 22 Mar 2016, 07:43 AM
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
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
DatePicker
Asked by
Shaindy
Top achievements
Rank 1
Answers by
Shaindy
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or