bootstrap-timepicker icon indicating copy to clipboard operation
bootstrap-timepicker copied to clipboard

Hours can go negative when defaultTime is set to false

Open carpeliam opened this issue 11 years ago • 4 comments

If defaultTime is set to false, and the user clicks the down arrow for either hours or minutes (or seconds if they're enabled), then the hour will be set to -1. (If seconds are enabled, minutes are properly decremented to 59.) This only happens the first time the timepicker popup is rendered.

I created a jsfiddle example of this here.

carpeliam avatar Dec 30 '13 16:12 carpeliam

I did some quick debugging- if your cursor is focused on the input element and you click the decrementHour link, this triggers a blur event on the input, which causes the clear() method to get called, which sets hour to an empty string. Maybe clear() shouldn't be called if the new focus is within the $widget... I dunno, I'll have to take a closer look later on.

carpeliam avatar Jan 18 '14 00:01 carpeliam

I just wanted to post an update, since I just ran into this problem: I tested to see if the negative value could be saved into the DB, and it turned out to save null, so no problem there (...still, the UI shows '-1', which isn't right). For me (without forking), the best solution is to pass in an empty string as the defaultTime. This will keep the unedited controls showing blank, and when they click in the element to edit, it will show as '1:00 AM'. This may not be ideal, but at least the user will not be able to select a negative time value.
I hope this helps someone!

bryanweaver avatar Dec 11 '14 15:12 bryanweaver

+1 Thanks @bryanweaver for the temporary solution however I still have the negative issue when they click down.

Braunson avatar Feb 15 '15 16:02 Braunson

Solution: I think we should set the defaultTime once again, the timepicker has a function name setDefaultTime after set it we never get the negative issue like this $('#birthTime').timepicker('setDefaultTime',"11:00 AM");

tungnt25 avatar Jun 17 '16 07:06 tungnt25