Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Timepicker init time change

How to dynamically change init time in Bootstrap Timepicker?

http://jdewit.github.com/bootstrap-timepicker/

Thanks for any help!

like image 499
user1654667 Avatar asked Dec 12 '22 22:12

user1654667


2 Answers

If you don't want to use the current time (which is the one by default), you can either use the options on initialization :

$('someSelector').timepicker({defaultTime: '11:42 PM'});

Or you can use the value attribute of the input (which simplifies the initialization for several time pickers) :

<input type="text" class="myClass input-small" value="12:42 PM">
$('.myClass').timepicker({defaultTime: 'value'});

Demo (jsfiddle)

like image 190
Sherbrow Avatar answered Dec 17 '22 22:12

Sherbrow


I'm the author the timepicker.

The 'value' option for default time has been deprecated. You have a variety of ways to set the default time to a specific value

set the value attribute

<div class="bootstrap-timepicker">
    <input id="timepicker" type="text" value="12:45 AM"/>
</div>

or set the data attribute to override the config option

<div class="bootstrap-timepicker">
    <input id="timepicker" type="text" data-default-value="12:45 AM"/>
</div>

or on init

$('#timepicker').timepicker({
    defaultValue: '12:45 AM'
});

or call the setTime method

$('#timepicker').timepicker();
$('#timepicker').timepicker('setTime', '12:45');  

Just open an issue on github if you have any problems!

like image 31
jdewit Avatar answered Dec 18 '22 00:12

jdewit