Datepicker onBlur event after using the calendar popup does not contain value.

2 Answers 2475 Views
DatePicker
German
Top achievements
Rank 1
German asked on 16 Feb 2023, 09:53 PM
The onBlur event the fires after the user clicks on the date in the calendar popup doesn't contain the value that's now in the datepicker. The onBlur that fires after a date is input to the text box and blurred does contain the value. Without that consistency, I am foreced to use the onChange event which is a very different implementation, which comes with a different set of challenges. Any advice?

2 Answers, 1 is accepted

Sort by
0
Accepted
Wissam
Telerik team
answered on 22 Feb 2023, 02:04 PM

Hello, German,

Basically,  the DatePicker blur event is fired for more than one component that is used inside of it (which is what you found in your research). In addition, you can get the data of the onBlur event using `e.relatedTarget.value`:

Nevertheless, I cannot help but agree that it would be more convenient to have something like `e.value` return the data without having to use `e.target.value` and `e.relatedTarget.value` as I did in the example above. Therefore,  I am logging an enhancement for research on implementing such functionality:

Regards,
Wissam
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
Wissam
Telerik team
answered on 20 Feb 2023, 01:47 PM

Hi, German,

I would suggest handling the DatePicker component in controlled mode which will allow us to store its value in a state variable and access it in the onBlur event handler:

For more information about handling the DatePicker in controlled mode, you can check the below article:

I hope this matches what you need, but please let us know if you have any further questions.

Regards,
Wissam
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

German
Top achievements
Rank 1
commented on 20 Feb 2023, 02:26 PM

After some further digging I have more information to add to this.

I am using the DatePicker in controlled mode, and I am listening to the onBlur event.

What I realized, however, is that the target of the onBlur event the fires after a user clicks on a date in the calendar popup is a div, not the input, and that focus then gets put on the input box itself. If I then listen for the input's onBlur, I have what I need. It's manageable, but it just seems like the onBlur event should not be firing when it is, not in that particular case.

Tags
DatePicker
Asked by
German
Top achievements
Rank 1
Answers by
Wissam
Telerik team
Share this question
or