mirror of
https://github.com/uxsolutions/bootstrap-datepicker.git
synced 2026-01-25 16:46:28 +00:00
Merge branch 'toggle-active-option' of https://github.com/ximi/bootstrap-datepicker into ximi-toggle-active-option
Conflicts: js/bootstrap-datepicker.js
This commit is contained in:
commit
db034d5477
@ -59,6 +59,12 @@ If true, displays a "Clear" button at the bottom of the datepicker to clear the
|
||||
.. figure:: _static/screenshots/option_clearbtn.png
|
||||
:align: center
|
||||
|
||||
toggleActive
|
||||
--------
|
||||
|
||||
Boolean. Default: true
|
||||
|
||||
If true, selecting the currently active date in the datepicker will unset the respective date. This option is always true when the multidate option is being used.
|
||||
|
||||
container
|
||||
-----------
|
||||
|
||||
23
js/bootstrap-datepicker.js
vendored
23
js/bootstrap-datepicker.js
vendored
@ -1105,23 +1105,25 @@
|
||||
if (!date){
|
||||
this.dates.clear();
|
||||
}
|
||||
if (this.o.multidate === 1 && ix === 0){
|
||||
// single datepicker, don't remove selected date
|
||||
else if (ix !== -1){
|
||||
if(this.o.multidate === true || this.o.multidate > 1 || this.o.toggleActive){
|
||||
this.dates.remove(ix);
|
||||
}
|
||||
}
|
||||
else if (this.o.multidate === false) {
|
||||
this.dates.clear();
|
||||
this.dates.push(date);
|
||||
}
|
||||
else {
|
||||
if (ix !== -1){
|
||||
this.dates.remove(ix);
|
||||
}
|
||||
else {
|
||||
//if (ix !== -1){
|
||||
// this.dates.remove(ix);
|
||||
//}
|
||||
//else {
|
||||
this.dates.push(date);
|
||||
}
|
||||
if (typeof this.o.multidate === 'number')
|
||||
while (this.dates.length > this.o.multidate)
|
||||
this.dates.remove(0);
|
||||
//}
|
||||
//if (typeof this.o.multidate === 'number')
|
||||
// while (this.dates.length > this.o.multidate)
|
||||
// this.dates.remove(0);
|
||||
}
|
||||
},
|
||||
|
||||
@ -1502,6 +1504,7 @@
|
||||
beforeShowMonth: $.noop,
|
||||
calendarWeeks: false,
|
||||
clearBtn: false,
|
||||
toggleActive: true,
|
||||
daysOfWeekDisabled: [],
|
||||
datesDisabled: [],
|
||||
endDate: Infinity,
|
||||
|
||||
@ -334,6 +334,126 @@ test('Clear Button: hides datepicker if autoclose is on', function(){
|
||||
|
||||
});
|
||||
|
||||
test('Active Toggle Default: when active date is selected it is unset', function(){
|
||||
var input = $('<input />')
|
||||
.appendTo('#qunit-fixture')
|
||||
.val('2012-03-05')
|
||||
.datepicker({
|
||||
format: 'yyyy-mm-dd',
|
||||
}),
|
||||
dp = input.data('datepicker'),
|
||||
picker = dp.picker,
|
||||
target;
|
||||
|
||||
// open our datepicker
|
||||
input.focus();
|
||||
|
||||
// Initial value is selected
|
||||
ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 selected');
|
||||
|
||||
// click on our active date
|
||||
target = picker.find('.datepicker-days .day.active');
|
||||
target.click();
|
||||
|
||||
// make sure it's no longer set
|
||||
equal(input.val(),'',"Input value has been cleared.");
|
||||
});
|
||||
|
||||
test('Active Toggle Multidate Default: when one of the active dates is selected it is unset', function(){
|
||||
var input = $('<input />')
|
||||
.appendTo('#qunit-fixture')
|
||||
.val('2012-03-05')
|
||||
.datepicker({
|
||||
format: 'yyyy-mm-dd',
|
||||
multidate: true
|
||||
}),
|
||||
dp = input.data('datepicker'),
|
||||
picker = dp.picker,
|
||||
target;
|
||||
|
||||
// open our datepicker
|
||||
input.focus();
|
||||
|
||||
// Initial value is selected
|
||||
ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 in dates');
|
||||
|
||||
// Select additional date
|
||||
target = picker.find('.datepicker-days tbody td:nth(7)');
|
||||
target.click();
|
||||
datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 4), '2012-03-04 in dates');
|
||||
datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
|
||||
equal(input.val(), '2012-03-05,2012-03-04');
|
||||
|
||||
// Unselect additional date
|
||||
target = picker.find('.datepicker-days tbody td:nth(7)');
|
||||
target.click();
|
||||
ok(dp.dates.contains(UTCDate(2012, 2, 4)) === -1, '2012-03-04 no longer in dates');
|
||||
datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
|
||||
equal(input.val(), '2012-03-05');
|
||||
});
|
||||
|
||||
test('Active Toggle Disabled: when active date is selected it remains', function(){
|
||||
var input = $('<input />')
|
||||
.appendTo('#qunit-fixture')
|
||||
.val('2012-03-05')
|
||||
.datepicker({
|
||||
format: 'yyyy-mm-dd',
|
||||
toggleActive: false
|
||||
}),
|
||||
dp = input.data('datepicker'),
|
||||
picker = dp.picker,
|
||||
target;
|
||||
|
||||
// open our datepicker
|
||||
input.focus();
|
||||
|
||||
// Initial value is selected
|
||||
ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 selected');
|
||||
|
||||
// click on our active date
|
||||
target = picker.find('.datepicker-days .day.active');
|
||||
target.click();
|
||||
|
||||
// make sure it's still set
|
||||
ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 still selected');
|
||||
datesEqual(dp.viewDate, UTCDate(2012, 2, 5));
|
||||
equal(input.val(), '2012-03-05');
|
||||
});
|
||||
|
||||
test('Active Toggle Multidate Disabled: when activeToggle is set to false, but multidate is set, the option is ignored and selecting an active date it is unset', function(){
|
||||
var input = $('<input />')
|
||||
.appendTo('#qunit-fixture')
|
||||
.val('2012-03-05')
|
||||
.datepicker({
|
||||
format: 'yyyy-mm-dd',
|
||||
multidate: true,
|
||||
toggleActive: false
|
||||
}),
|
||||
dp = input.data('datepicker'),
|
||||
picker = dp.picker,
|
||||
target;
|
||||
|
||||
// open our datepicker
|
||||
input.focus();
|
||||
|
||||
// Initial value is selected
|
||||
ok(dp.dates.contains(UTCDate(2012, 2, 5)) !== -1, '2012-03-05 in dates');
|
||||
|
||||
// Select additional date
|
||||
target = picker.find('.datepicker-days tbody td:nth(7)');
|
||||
target.click();
|
||||
datesEqual(dp.dates.get(-1), UTCDate(2012, 2, 4), '2012-03-04 in dates');
|
||||
datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
|
||||
equal(input.val(), '2012-03-05,2012-03-04');
|
||||
|
||||
// Unselect additional date
|
||||
target = picker.find('.datepicker-days tbody td:nth(7)');
|
||||
target.click();
|
||||
ok(dp.dates.contains(UTCDate(2012, 2, 4)) === -1, '2012-03-04 no longer in dates');
|
||||
datesEqual(dp.viewDate, UTCDate(2012, 2, 4));
|
||||
equal(input.val(), '2012-03-05');
|
||||
});
|
||||
|
||||
test('DaysOfWeekDisabled', function(){
|
||||
var input = $('<input />')
|
||||
.appendTo('#qunit-fixture')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user