Search code examples
asp.nethidebootstrap-datetimepickereonasdan-datetimepicker

How to close bootstrap datetimepicker when date is selected


I am using bootstrap datetimepicker (http://eonasdan.github.io/bootstrap-datetimepicker/Installing/).

When I select the date the picker does not hides and I have to click outside to close it. How to close datetimepicker when date is selected/clicked?

<div class="col-sm-3">
  <asp:TextBox ID="date2" class="form-control" runat="server"
    onfocus="this.style.backgroundColor='yellow'"
    onblur="this.style.backgroundColor='cyan'"/>
  <script type="text/javascript">
    $(function () {
      $('#date2').datetimepicker();
    });
  </script> 
</div>

Solution

  • You can force the datetimepicker to hide itself with the following piece of code.

    $('#date2').data("DateTimePicker").hide();
    

    For other functions like hide please consider checking out the documentation.