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

DateTimePicker not saving after editing text

4 Answers 206 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Veteran
Scott asked on 28 Aug 2020, 07:22 PM
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. 

4 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 02 Sep 2020, 09:42 AM

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).

0
Scott
Top achievements
Rank 1
Veteran
answered on 02 Sep 2020, 08:40 PM

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!

0
Dinko | Tech Support Engineer
Telerik team
answered on 07 Sep 2020, 11:53 AM

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/.

0
Scott
Top achievements
Rank 1
Veteran
answered on 09 Sep 2020, 06:08 PM

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;
                }

Tags
DateTimePicker
Asked by
Scott
Top achievements
Rank 1
Veteran
Answers by
Dinko | Tech Support Engineer
Telerik team
Scott
Top achievements
Rank 1
Veteran
Share this question
or