Reputation: 181
I need to display the bootstrap datetimepicker for an input field. It's working but not displaying properly. The calender is displayed but I can't see the option to change time.
HTML code:
<div class="form-group">
<p>Date of Birth <span>*</span></p>
<input type="text" name="dob" id="dob" max="3000-12-31" value="2012-05-15 21:05" class="form-control input-sm" required/>
</div>
JavaScript Code:
$(document).ready(function() {
$(function () {
$('#dob').datetimepicker();
});
});`
List of dependencies I've used:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
Here's the fiddle: JSfiddle
Here are pictures of the calendar drop down:
Upvotes: 0
Views: 7102
Reputation: 31502
From the Installing section of the docs, the components requires:
You are missing jQuery, momentjs and bootstrap.js in your fiddle.
Please note that:
format
option to tell the picker in which format the date should be formatted. You can use 'YYYY-MM-DD HH:mm'
.You will have the following error in the console:
Uncaught Error: datetimepicker component should be placed within a non-static positioned container
if you don't change your HTML structure, see docs for some examples.
You have to use data-date-*
, if you want to initialize options of the picker via data attributes. You can use data-date-max-date
to set maxDate
option. See here for futher examples.
Here a working sample:
$('#dob').datetimepicker({
format: 'YYYY-MM-DD HH:mm'
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
<div class="col-lg-12">
<p>Date of Birth <span>*</span></p>
<input type="text" name="dob" id="dob" data-date-max-date="3000-12-31" value="2012-05-15 21:05" class="form-control input-sm" required/>
</div>
Upvotes: 0