Problem with the new IsInputRestrictedToSelectableDates property in the DatePicker

5 posts, 0 answers
  1. Shaindy
    Shaindy avatar
    3 posts
    Member since:
    Sep 2014

    Posted 17 Mar Link to this post

    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.

  2. Shaindy
    Shaindy avatar
    3 posts
    Member since:
    Sep 2014

    Posted 17 Mar in reply to Shaindy Link to this post

    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?

  3. UI for WPF is Visual Studio 2017 Ready
  4. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 21 Mar Link to this post

    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.
  5. Shaindy
    Shaindy avatar
    3 posts
    Member since:
    Sep 2014

    Posted 22 Mar in reply to Kalin Link to this post

    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?

  6. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 22 Mar Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready