Reputation: 2619
I'm trying out this datepicker plugin. i can't seem to get it to work. Is bootstrap not compatible with jquery 1.9+ ?
<div class="alert alert-error" id="alert">
<strong>Oh snap!</strong>
</div>
<table class="table">
<thead>
<tr>
<th>
Start date
<a href="#" class="btn small" id="date-start" data-date-format="yyyy-mm-dd" data-date="2012-02-20">Change</a>
</th>
<th>
End date
<a href="#" class="btn small" id="date-end" data-date-format="yyyy-mm-dd" data-date="2012-02-25">Change</a>
</th>
</tr>
</thead>
<tbody>
<tr>
<td id="date-start-display">2012-02-20</td>
<td id="date-end-display">2012-02-25</td>
</tr>
</tbody>
</table>
any idea what i'm missing? Here is my code
Upvotes: 0
Views: 1644
Reputation: 10712
There you go .. http://jsfiddle.net/jbDUe/2/ you forgot to load the datepicker-plugin.js.
I have added it as an external resource and everything is working.
Use this GitHub CDN to load your file in jsFiddle external resources: https://raw.github.com/eternicode/bootstrap-datepicker/master/js/bootstrap-datepicker.js
var startDate = new Date(2012,1,20);
var endDate = new Date(2012,1,25);
$('#date-start')
.datepicker()
.on('changeDate', function(ev){
if (ev.date.valueOf() > endDate.valueOf()){
$('#alert').show().find('strong').text('The start date must be before the end date.');
} else {
$('#alert').hide();
startDate = new Date(ev.date);
$('#date-start-display').text($('#date-start').data('date'));
}
$('#date-start').datepicker('hide');
});
$('#date-end')
.datepicker()
.on('changeDate', function(ev){
if (ev.date.valueOf() < startDate.valueOf()){
$('#alert').show().find('strong').text('The end date must be after the start date.');
} else {
$('#alert').hide();
endDate = new Date(ev.date);
$('#date-end-display').text($('#date-end').data('date'));
}
$('#date-end').datepicker('hide');
});
Upvotes: 2