Bootstrap datetimepicker: show calendar pop-up when a user clicks on input

I'll-Be-Back picture I'll-Be-Back · Jul 28, 2017 · Viewed 18.9k times · Source

Is there a way to show calendar when a user clicks on input as well? Right now I have to click on the calendar icon which will then show calendar.

HTML:

<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>

JavaScript:

$(function() {
  $('#datetimepicker1').datetimepicker();
});


Example: https://jsfiddle.net/8jpmkcr5/81/

Answer

VincenzoC picture VincenzoC · Jul 28, 2017

You can simply use allowInputToggle option setting it to true (Default: false). As docs says:

If true, the picker will show on textbox focus and icon click when used in a button group

Here a working live sample:

$('#datetimepicker1').datetimepicker({
  allowInputToggle: true
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>

<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>