3

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>
VincenzoC
  • 30,117
  • 12
  • 90
  • 112
kuldeep singh
  • 367
  • 1
  • 5
  • 14

1 Answers1

4

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.

Izzet Yildirim
  • 640
  • 1
  • 11
  • 19
  • Thanks Izzet! i think i am doing something wrong... – kuldeep singh Jan 07 '17 at 12:01
  • 3
    Then try this: `$("#date").on("dp.change", function() { $("#date2").data("DateTimePicker").hide(); });` Also, there is an option called `keepOpen` that you could pass as **false** in the constructor. – Izzet Yildirim Jan 07 '17 at 12:37
  • Thanks a lot Izzet. It is working fine. Can we hide time part from the date. – kuldeep singh Jan 07 '17 at 14:05
  • To hide the time part, pass format option in the initialization method as MM/dd/YYYY. Please check out the documentation in this regard: http://eonasdan.github.io/bootstrap-datetimepicker/Options/#format – Izzet Yildirim Jan 07 '17 at 14:24