From ecbaa92f8b9b609f8a1f6b9d76b017a37a6e8310 Mon Sep 17 00:00:00 2001 From: lucas3003 Date: Wed, 14 Dec 2016 14:25:07 -0200 Subject: [PATCH 1/5] Change month when dateMinLimit is set --- src/js/angular-datepicker.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index 3f56fcc..ef49a11 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -174,6 +174,8 @@ $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM')); $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd')); $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy')); + + setDaysInMonth($scope.monthNumber, $scope.year); } , resetToMaxDate = function resetToMaxDate() { @@ -487,6 +489,12 @@ setDaysInMonth($scope.monthNumber, $scope.year); setInputValue(); }; + + $scope.$watch('dateMinLimit', function(){ + if($scope.dateMinLimit) + resetToMinDate(); + }) + $scope.setNewYear = function setNewYear(year) { From 04db8c78ea63f8754ccfa67024c86c598ee1b7d8 Mon Sep 17 00:00:00 2001 From: lucas3003 Date: Tue, 27 Dec 2016 08:50:13 -0200 Subject: [PATCH 2/5] Adapting code to deregister the watcher --- src/js/angular-datepicker.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index ef49a11..c8e8336 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -175,7 +175,7 @@ $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd')); $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy')); - setDaysInMonth($scope.monthNumber, $scope.year); + setDaysInMonth($scope.monthNumber, $scope.year); } , resetToMaxDate = function resetToMaxDate() { @@ -378,6 +378,11 @@ setInputValue(); } } + }) + , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue){ + if(newValue){ + resetToMinDate(); + } }); $scope.nextMonth = function nextMonth() { @@ -488,13 +493,7 @@ $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM')); setDaysInMonth($scope.monthNumber, $scope.year); setInputValue(); - }; - - $scope.$watch('dateMinLimit', function(){ - if($scope.dateMinLimit) - resetToMinDate(); - }) - + }; $scope.setNewYear = function setNewYear(year) { @@ -839,6 +838,7 @@ $scope.$on('$destroy', function unregisterListener() { unregisterDataSetWatcher(); + unRegisterDateMinLimitWatcher(); thisInput.off('focus click focusout blur'); angular.element(theCalendar).off('mouseenter mouseleave focusin'); angular.element($window).off('click focus focusin', onClickOnWindow); From 869afed8454eb6f90ef2597e138da18686cf2aef Mon Sep 17 00:00:00 2001 From: lucas3003 Date: Tue, 27 Dec 2016 08:54:15 -0200 Subject: [PATCH 3/5] Typo --- src/js/angular-datepicker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index c8e8336..aea6fe7 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -838,7 +838,7 @@ $scope.$on('$destroy', function unregisterListener() { unregisterDataSetWatcher(); - unRegisterDateMinLimitWatcher(); + unregisterDateMinLimitWatcher(); thisInput.off('focus click focusout blur'); angular.element(theCalendar).off('mouseenter mouseleave focusin'); angular.element($window).off('click focus focusin', onClickOnWindow); From fe0e7250dd7f9e1b286b8e3bc36b37fb5c91ecb1 Mon Sep 17 00:00:00 2001 From: lucas3003 Date: Tue, 27 Dec 2016 09:47:15 -0200 Subject: [PATCH 4/5] Added watcher to date-max-limit and date-format --- src/js/angular-datepicker.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index aea6fe7..19006ea 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -183,6 +183,8 @@ $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM')); $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd')); $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy')); + + setDaysInMonth($scope.monthNumber, $scope.year); } , prevYear = function prevYear() { @@ -383,6 +385,14 @@ if(newValue){ resetToMinDate(); } + }) + , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue){ + if(newValue) + resetToMaxDate(); + }) + , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue){ + if(newValue) + setInputValue(); }); $scope.nextMonth = function nextMonth() { @@ -839,6 +849,8 @@ unregisterDataSetWatcher(); unregisterDateMinLimitWatcher(); + unregisterDateMaxLimitWatcher(); + unregisterDateFormatWatcher(); thisInput.off('focus click focusout blur'); angular.element(theCalendar).off('mouseenter mouseleave focusin'); angular.element($window).off('click focus focusin', onClickOnWindow); From 4178866edc82a749c325fd3b187488cf6ae7e74c Mon Sep 17 00:00:00 2001 From: lucas3003 Date: Tue, 27 Dec 2016 11:23:33 -0200 Subject: [PATCH 5/5] Added { } curlyes on if statements --- src/js/angular-datepicker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index 19006ea..1732d47 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -387,12 +387,14 @@ } }) , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue){ - if(newValue) + if(newValue){ resetToMaxDate(); + } }) , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue){ - if(newValue) + if(newValue){ setInputValue(); + } }); $scope.nextMonth = function nextMonth() {