From 140ae52577df526b266182b1f3e24ac5aeed5190 Mon Sep 17 00:00:00 2001 From: jgutix Date: Wed, 11 Jan 2017 17:08:08 -0700 Subject: [PATCH 1/3] Comparing the viewDate to startDate and endDate instead of date for resetting the viewDate, this will prevent to reset the view of the month if the view already moved away from the current selected date. --- js/bootstrap-datetimepicker.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/js/bootstrap-datetimepicker.js b/js/bootstrap-datetimepicker.js index c7ba8bbe..3cd3e190 100644 --- a/js/bootstrap-datetimepicker.js +++ b/js/bootstrap-datetimepicker.js @@ -418,6 +418,7 @@ this.picker.hide(); $(window).off('resize', this.place); this.viewMode = this.startViewMode; + this.viewDate = new Date(this.date); this.showMode(); if (!this.isInput) { $(document).off('mousedown', this.hide); @@ -677,11 +678,11 @@ if (fromArgs) this.setValue(); - if (this.date < this.startDate) { + if (this.viewDate < this.startDate) { this.viewDate = new Date(this.startDate); - } else if (this.date > this.endDate) { + } else if (this.viewDate > this.endDate) { this.viewDate = new Date(this.endDate); - } else { + } else if(!this.viewDate){ this.viewDate = new Date(this.date); } this.fill(); From b6e17388b86b206b0bf202bc8d0805ef19718a1e Mon Sep 17 00:00:00 2001 From: jgutix Date: Tue, 14 Nov 2017 16:25:35 -0700 Subject: [PATCH 2/3] Reverting the change on the `update` method. Skipping the `this.update` call within `setDatesDisabled` otherwise it will reset the `viewDate` (aka issue #617) --- js/bootstrap-datetimepicker.js | 8 ++++---- tests/suites/options.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/js/bootstrap-datetimepicker.js b/js/bootstrap-datetimepicker.js index 3cd3e190..c548fb44 100644 --- a/js/bootstrap-datetimepicker.js +++ b/js/bootstrap-datetimepicker.js @@ -547,7 +547,7 @@ this.datesDisabled = $.map(this.datesDisabled, function (d) { return DPGlobal.parseDate(d, mThis.format, mThis.language, mThis.formatType, mThis.timezone).toDateString(); }); - this.update(); + this.fill(); this.updateNavArrows(); }, @@ -678,11 +678,11 @@ if (fromArgs) this.setValue(); - if (this.viewDate < this.startDate) { + if (this.date < this.startDate) { this.viewDate = new Date(this.startDate); - } else if (this.viewDate > this.endDate) { + } else if (this.date > this.endDate) { this.viewDate = new Date(this.endDate); - } else if(!this.viewDate){ + } else { this.viewDate = new Date(this.date); } this.fill(); diff --git a/tests/suites/options.js b/tests/suites/options.js index d52d1951..5ff0cec3 100644 --- a/tests/suites/options.js +++ b/tests/suites/options.js @@ -288,6 +288,23 @@ test('DaysOfWeekDisabled', function(){ ok(target.hasClass('disabled'), 'Day of week is disabled'); }); +test('setDatesDisabled', function(){ + var input = $('') + .appendTo('#qunit-fixture') + .val('2012-10-26') + .datetimepicker({ + format: 'yyyy-mm-dd', + }), + dp = input.data('datetimepicker'), + picker = dp.picker, + target; + + input.datetimepicker('setDatesDisabled', ['2012-10-28']); + input.focus(); + target = picker.find('.datetimepicker-days tbody td:nth(28)'); + ok(target.hasClass('disabled'), 'Set dates disabled'); +}); + test('startDate: Custom value', function(){ var input = $('') .appendTo('#qunit-fixture') From 0a0123e4e81a455cc3c00d85943611d79a1f2cf3 Mon Sep 17 00:00:00 2001 From: jgutix Date: Tue, 14 Nov 2017 16:40:35 -0700 Subject: [PATCH 3/3] Updating the way the arguments are handled. --- tests/run-qunit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-qunit.js b/tests/run-qunit.js index effdc3f1..84d5563f 100644 --- a/tests/run-qunit.js +++ b/tests/run-qunit.js @@ -53,8 +53,8 @@ page.onError = function (msg, trace) { console.log(' ', item.file, ':', item.line); }) } - -var _openPath = phantom.args[0].replace(/^.*(\\|\/)/, ''); +args = system.args.toString().split(','); +var _openPath = args[1].replace(/^.*(\\|\/)/, ''); var openPath = _openPath; var origdir = '../js/'; var basedir = '../instrumented/';