-1

I want bootstrap datepicker 3 to remain always open. I have tried all previous solutions but I guess they are not applicable on version 3. I can show it on 'dp.hide' but it hangs my browser because of inefficiency.

Any other solutions are appreciable. I don't want calendar to be closed when I click somewhere else on browser.

Here is JavaScript code

<script type="text/javascript">
    $(function () {
        $('#datetimepicker10').datetimepicker({
            viewMode: 'years',
            format: 'MM/YYYY',
            keepOpen: true
        }).on('dp.update', function () {
            $('#datetimepicker10').datetimepicker("show");
        });

        $('#datetimepicker10').data("DateTimePicker").show();

    });
</script>

Here is html

<div class="form-group">
    <div class='input-group date' id='datetimepicker10'>
        <input type='text' class="form-control" />
        <span class="input-group-addon">
            <span class="glyphicon glyphicon-calendar">
            </span>
        </span>
    </div>
</div>
VincenzoC
  • 30,117
  • 12
  • 90
  • 112
M Usama Alvi
  • 187
  • 1
  • 15

2 Answers2

1

In case that you don't want to use the inline mode you can always use the debug option. Something annoying for me but if it works for you...

$('#myDatepicker').datetimepicker({
  debug: true
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/25c11d79/build/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />


<br/>
<!--Space for the fiddle-->
<div class="container">
  <div class="row">
    <div class='col-sm-6'>
      <div class="form-group">
        <div class='input-group date' id='myDatepicker'>
          <input type='text' class="form-control" />
          <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
          </span>
        </div>
      </div>
    </div>
  </div>
</div>
William-H-M
  • 1,050
  • 1
  • 13
  • 19
0

Instead of using input, initialize the date in a div and set inline to true.

$("#datetimepicker").datetimepicker({
    format: 'DD/MM/YYYY HH',
    inline: true,
    sideBySide: true
});
function showDate()
{
   console.log($('#datetimepicker').data("DateTimePicker").date());
}
.date
{
    max-width:200px
}
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/master/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<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.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<script src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/master/src/js/bootstrap-datetimepicker.js"></script>

<div class="date" id="datetimepicker"></div>
<button onclick="showDate()">Get Date</button>

If multiple datetimepickers are need to be shown open always, set $.fn.datetimepicker.defaults.inline = true; before initializing them. No need to pass inline: true in options in that case.

Note: Be careful on setting the format. If the format doesn't include time, then time component will not be displayed. If unset, no problem.

Vignesh Raja
  • 7,927
  • 1
  • 33
  • 42