From 3a3cebe0b383e710ac479c64fa09a91a2e4b3e67 Mon Sep 17 00:00:00 2001 From: Maximilian Zimmer Date: Fri, 4 Apr 2014 12:42:44 +0300 Subject: [PATCH 1/8] Add option to prevent clearing of date if the currently active date is clicked --- js/bootstrap-datepicker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 6fbbeb3..1db103e 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -1017,7 +1017,7 @@ if (!date){ this.dates.clear(); } - else if (ix !== -1){ + else if (this.o.toggleActive && ix !== -1){ this.dates.remove(ix); } else { @@ -1393,6 +1393,7 @@ beforeShowDay: $.noop, calendarWeeks: false, clearBtn: false, + toggleActive: true, daysOfWeekDisabled: [], endDate: Infinity, forceParse: true, From fad877b084895a078af4808d9c34ea9b8b536516 Mon Sep 17 00:00:00 2001 From: Maximilian Zimmer Date: Fri, 4 Apr 2014 17:18:26 +0300 Subject: [PATCH 2/8] Updated documentation --- docs/options.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/options.rst b/docs/options.rst index f75a02f..5788ff5 100644 --- a/docs/options.rst +++ b/docs/options.rst @@ -51,6 +51,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 clear the input value. .. _daysofweekdisabled: From 2b8ad2817f43cd5745a9cb731b9c528b7e08e736 Mon Sep 17 00:00:00 2001 From: Maximilian Zimmer Date: Fri, 4 Apr 2014 17:35:40 +0300 Subject: [PATCH 3/8] Ignore activeToggle option if multidate option is set --- js/bootstrap-datepicker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 1db103e..b9c73aa 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -1017,7 +1017,7 @@ if (!date){ this.dates.clear(); } - else if (this.o.toggleActive && ix !== -1){ + else if (!this.o.multidate && this.o.toggleActive && ix !== -1){ this.dates.remove(ix); } else { From d47fb0d830d5bea01dcbf1ae44eb5aa5c8c03169 Mon Sep 17 00:00:00 2001 From: Maximilian Zimmer Date: Fri, 4 Apr 2014 17:39:34 +0300 Subject: [PATCH 4/8] Updated docs with updat related to multidate --- docs/options.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/options.rst b/docs/options.rst index 5788ff5..407bac1 100644 --- a/docs/options.rst +++ b/docs/options.rst @@ -56,7 +56,7 @@ toggleActive Boolean. Default: true -If true, selecting the currently active date in the datepicker will clear the input value. +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. .. _daysofweekdisabled: From 0552a98738f7d0781a0c1b4faf356e667cf0735c Mon Sep 17 00:00:00 2001 From: Maximilian Zimmer Date: Fri, 4 Apr 2014 18:21:39 +0300 Subject: [PATCH 5/8] One more small bugfix --- js/bootstrap-datepicker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index b9c73aa..9219d8f 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -1017,8 +1017,8 @@ if (!date){ this.dates.clear(); } - else if (!this.o.multidate && this.o.toggleActive && ix !== -1){ - this.dates.remove(ix); + else if ((this.o.multidate > 1 || this.o.toggleActive) && ix !== -1){ + this.dates.remove(ix); } else { this.dates.push(date); From 7b4750a31d6c132a6eb0e2ed3b1dcd88a90056dd Mon Sep 17 00:00:00 2001 From: Maximilian Zimmer Date: Fri, 4 Apr 2014 18:29:55 +0300 Subject: [PATCH 6/8] One final bugfix that handles all combinations of options we need to consider --- js/bootstrap-datepicker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 9219d8f..86b49bf 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -1017,8 +1017,10 @@ if (!date){ this.dates.clear(); } - else if ((this.o.multidate > 1 || this.o.toggleActive) && ix !== -1){ - this.dates.remove(ix); + else if (ix !== -1){ + if(this.o.multidate === true || this.o.multidate > 1 || this.o.toggleActive){ + this.dates.remove(ix); + } } else { this.dates.push(date); From d7325246653a9ec9cef594b12ef12d2d3120509b Mon Sep 17 00:00:00 2001 From: Maximilian Zimmer Date: Fri, 4 Apr 2014 18:30:13 +0300 Subject: [PATCH 7/8] Added tests --- tests/suites/options.js | 120 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/tests/suites/options.js b/tests/suites/options.js index 6682058..de8a049 100644 --- a/tests/suites/options.js +++ b/tests/suites/options.js @@ -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 = $('') + .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 = $('') + .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 = $('') + .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 = $('') + .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 = $('') .appendTo('#qunit-fixture') From 854775bd4928eeea1f58a4e08e40e026446c9832 Mon Sep 17 00:00:00 2001 From: Maximilian Zimmer Date: Fri, 4 Apr 2014 18:34:43 +0300 Subject: [PATCH 8/8] Changed spaces to tabs --- js/bootstrap-datepicker.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/bootstrap-datepicker.js b/js/bootstrap-datepicker.js index 86b49bf..a9e1908 100644 --- a/js/bootstrap-datepicker.js +++ b/js/bootstrap-datepicker.js @@ -1018,9 +1018,9 @@ this.dates.clear(); } else if (ix !== -1){ - if(this.o.multidate === true || this.o.multidate > 1 || this.o.toggleActive){ - this.dates.remove(ix); - } + if(this.o.multidate === true || this.o.multidate > 1 || this.o.toggleActive){ + this.dates.remove(ix); + } } else { this.dates.push(date); @@ -1395,7 +1395,7 @@ beforeShowDay: $.noop, calendarWeeks: false, clearBtn: false, - toggleActive: true, + toggleActive: true, daysOfWeekDisabled: [], endDate: Infinity, forceParse: true,