Dhaval Dhaval - 1 year ago 80
Javascript Question

How to use Bootstrap datetime control

I need to use datetime picker control in my MVC 4 application.
For that, I have installed

bootstrap 3-datetimepicker
nuget package and below related files are referred.

<link href="Content/bootstrap.min.css" rel="stylesheet" />
<link href="Content/bootstrap-datetimepicker.css" rel="stylesheet" />
<!--renamed - .less file to .css and referred here !>
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script src="Scripts/bootstrap.js"></script>
<script src="Scripts/bootstrap-datetimepicker.min.js"></script>

Html code:

<div class="container">
<div class="row">
<input type="text" id="dpicker" class="form-control" />

JS code:

$(function() {
$("#dpicker").datetimepicker({ format: 'mm-dd-yyyy' });

Though, on click of textbox no date picker is open.

What is the issue in above code to use bootstrap date time picker control ?


Answer Source

Add date class to input first parent, i.e: <div class='row date'>.

Then it will work.

Here is working snippet

    format: 'mm-dd-yyyy'
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.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.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.min.js"></script>

 <div class="container">
      <div class="row date">
        <input type="text" id="dpicker" class="form-control" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download