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

Timepicker Move focus to similar time

3 Answers 37 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
NHJ
Top achievements
Rank 1
NHJ asked on 16 Dec 2019, 04:26 AM
Hi,

The TimePicker is set to 30 minute intervals by default.

So if the time fits in that interval, the first time you open the dropbox, it will be focused at that time.


However, if the initial or recalled time is equal to 32 minutes or 49 minutes, the focus is set at 00:00.

Is there a way to round and focus to nearby times?

3:29-> 3:30 Focusing

2:14-> 2:00 Focusing

I don't want to change the value.

The focus only needs to move near that time.

3 Answers, 1 is accepted

Sort by
0
Accepted
Teya
Telerik team
answered on 17 Dec 2019, 02:23 PM

Hi Nam,

You can try something similar to the approach suggested in the following Dojo:

https://dojo.telerik.com/AyeXOGId

1. Subscribe to the Open event of the Kendo Timepicker

2. Get the current time in minutes and check whether it is divisible by 30

3. If not, round up the value to the nearest time divisible by 30

4. Select the respective time from the list

 

I hope this would be helpful.

Regards,
Teya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
NHJ
Top achievements
Rank 1
answered on 18 Dec 2019, 12:52 AM
Thank you for the answer!

Your help has helped me a lot. That code works for me!

There's one thing you want, is it harder to streamline your code?

I was surprised that the required code was longer than I thought.
0
Teya
Telerik team
answered on 19 Dec 2019, 09:08 AM

Hello Nam,

I am glad that the code is working fine for you.

Unfortunately, there is not much I can do for streamlining the code since there are a couple of things that need to be done in order to select a rounded-up value from the dropdown, without changing the value of the input itself. And such a method is currently not available out of the box.

Regards,
Teya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Date/Time Pickers
Asked by
NHJ
Top achievements
Rank 1
Answers by
Teya
Telerik team
NHJ
Top achievements
Rank 1
Share this question
or