Is there a way to add hour/minute label to eonasdan's bootstrap datetimepicker like shown in the screenshot?
Asked
Active
Viewed 3,068 times
2
-
1You'd probably have to tweak it yourself, but the maintainer would probably welcome the resulting PR. – ceejayoz May 30 '17 at 18:35
1 Answers
1
As ceejayoz stated in comments, the datetimepicker does not include this kind of functionality. The library is open source and you can customize the code and the look & feel as suggested.
Another appoach is to add dinamically a row under hours and minutes row when the picker is shown. You can add a listner to dp.show
event and then use jQuery to manipulate picker HTML.
Here a working sample:
$('#datetimepicker1').datetimepicker({
format: 'HH:mm'
});
$('#datetimepicker1').on('dp.show', function(){
// Check timepicker is visible
if( $('.timepicker').is(':visible') ){
// Get rows of the timepicker
var rows = $('.timepicker>.timepicker-picker>table>tbody>tr');
// Create html for custom text
var tr = '<tr class="customText"><td>hours</td><td class="separator"></td><td>minutes</td></tr>';
// Add custom HTML inside component
$(rows[1]).after(tr);
}
});
.bootstrap-datetimepicker-widget table tr.customText td {
height: 24px;
line-height: 24px;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
The datetimepicker has the debug
option that, if set to true
:
Will cause the date picker to stay open after a
blur
event.

VincenzoC
- 30,117
- 12
- 90
- 112
-
side question - how did you check the rendered HTML of the widget? Once the widget is expanded and you Right click -> Inspect Element with Firebug on the hour, the widget collapses and firebug HTML shows only the unexpanded widget HTML. – joym8 May 31 '17 at 13:36
-
@joym8 I've edited my answer, to inspect the endered HTML of the component you can set [`debug`](https://eonasdan.github.io/bootstrap-datetimepicker/Options/#debug) option to `true`. – VincenzoC May 31 '17 at 14:05