DateTimePicker not saving after editing text

5 posts, 0 answers
  1. Scott
    Scott avatar
    7 posts
    Member since:
    Aug 2020

    Posted 28 Aug 2020 Link to this post

    We have an issue where on a DateTimePicker, if you change the date, such as 8/29/2020 12:00 AM to 8/31/2020 12:00 AM, by editing the text in the field, on saving, it will not save the new date. It only seems to work if you click TAB after editing the text, or using the date picker button to change the date. Some users would like the ability to just change the test and click save, vs tabbing or using the date picker. 
  2. Dinko
    Admin
    Dinko avatar
    1259 posts

    Posted 02 Sep 2020 Link to this post

    Hi Scott,

    Thank you for the provided details.

    I am not sure what you mean here by saving the date. If I bind the SelectedValue property of the RadDateTimePicker to a property of type DateTime, the setter of the property is called each time when a new date is selected. Can you share your set-up so I can try to reproduce it on my side?

    Regards,
    Dinko
    Progress Telerik

    Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

  3. Scott
    Scott avatar
    7 posts
    Member since:
    Aug 2020

    Posted 02 Sep 2020 in reply to Dinko Link to this post

    Hi Dinko, I cannot provide you with my solution, however I am providing a couple of screen shots to see if that will help illustrate the issue. Note that in the first screen shot, date-1.jpg, I am just "textually" changing the date, not using the 9 square icon to select a date, or choosing the selection if it pops up. date-2.jpg illustrated how the date pops up if you textually change it. 

    If I click Save in my UI, it will not Save the date, and goes back to the previous one entered. Is this the way the RadDateTimePicker works, or is something wrong. Some of our users have complained that they don't want to select a date or use the 9 box, they just want to enter the date and click save.

    Thank you!

  4. Dinko
    Admin
    Dinko avatar
    1259 posts

    Posted 07 Sep 2020 Link to this post

    Hello Scott,

    Thank you for the provided details.

    I understand what you mean here. You are right that editing the text will not update the bound value. The update will happen when the user presses the enter key or focus different element. What you can do to achieve this behavior is to subscribe to the ParseDateTimeValue event of the RadDateTimePicker. In the event handler, you can check the IsParsingSuccessful property from the event arguments. If the parsing is successful you can set the bound property to the Result property from the event arguments.

    private void RadDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
    {
        if(args.IsParsingSuccessful)
        {
            var newValue = args.Result;
            var dateTimePicker = args.Source as RadDateTimePicker;
            if((this.DataContext as ViewModel).MyDateProperty != args.Result)
            {
                this.MyDate = args.Result;
            }
        }
    }

    Regards,
    Dinko
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  5. Scott
    Scott avatar
    7 posts
    Member since:
    Aug 2020

    Posted 09 Sep 2020 in reply to Dinko Link to this post

    Hey Dinko, thanks a ton for sending me the sample code! While I had to make a few modifications, it worked!

    For example, I had to make sure each RadDateTimePicker has an x:Name applied to it. In the code behind I made a small update. to get the code to work, I had to make a light adjustment for the args.Result. by referencing the SelectedDate parameter:

    if ((this.DataContext as MyPrivateModelView).MyInternalVariable !=
                        args.Result)
                    {
                        this.MyCustomDateInXAML.SelectedDate = args.Result;
                    }

Back to Top