Bootstrap datepicker - two datepickers updating each others start/end dates
I'm using the bootstrap-datepicker widget from eternicode.
I want two date pickers on my page, each updating the other;
Changing date1 should set the start date of date2.
Changing date2 should set the end date of date1.
Both dates should initially show today's date.
Here's what I have so far
var month = ("January February March April May June July August September
October November December").split(" ");
var now = new Date();
var nowformatted = now.getDate() + " " + month[now.getMonth()] + " " +
now.getFullYear();
var dpOptions = {
format: 'dd MM yyyy',
startDate: now,
setDate: now,
};
var datePicker1 = $("#date1").
val(nowformatted).
datepicker(dpOptions).
on('changeDate', function (e) {
datePicker2.datepicker('setStartDate', e.date);
datePicker2.datepicker('update');
});
var datePicker2 = $("#date2").
val(nowformatted).
datepicker(dpOptions).
on('changeDate', function (e) {
datePicker1.datepicker('setEndDate', e.date);
datePicker1.datepicker('update');
});
but it's causing chrome and FF to crash if date1 is changed BEFORE date2.
If date2 is changed first then the code works as intended.
I could use some input on whether this is a bug in the plugin or in the
way I've coded my implementation.
Here's a fiddle that doesn't actually crash the browser but it does hang
for a second on selecting the first date.
I should mention that I'm using bootstrap 3. This plugin was intended for
v2. Is this the problem?
[update] I tried a fiddle with bootstrap 2.3.2 - same hang on date1
selection so I'm guessing it's not the bootstrap version.
No comments:
Post a Comment