Skip to content
This repository was archived by the owner on Feb 18, 2022. It is now read-only.

Commit fd6a3d7

Browse files
authored
Merge pull request #214 from lucas3003/master
Change month when dateMinLimit is set
2 parents 71d9cce + 4178866 commit fd6a3d7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/js/angular-datepicker.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,17 @@
174174
$scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM'));
175175
$scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd'));
176176
$scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy'));
177+
178+
setDaysInMonth($scope.monthNumber, $scope.year);
177179
}
178180
, resetToMaxDate = function resetToMaxDate() {
179181

180182
$scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM');
181183
$scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM'));
182184
$scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd'));
183185
$scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));
186+
187+
setDaysInMonth($scope.monthNumber, $scope.year);
184188
}
185189
, prevYear = function prevYear() {
186190

@@ -376,6 +380,21 @@
376380
setInputValue();
377381
}
378382
}
383+
})
384+
, unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue){
385+
if(newValue){
386+
resetToMinDate();
387+
}
388+
})
389+
, unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue){
390+
if(newValue){
391+
resetToMaxDate();
392+
}
393+
})
394+
, unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue){
395+
if(newValue){
396+
setInputValue();
397+
}
379398
});
380399

381400
$scope.nextMonth = function nextMonth() {
@@ -486,7 +505,7 @@
486505
$scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM'));
487506
setDaysInMonth($scope.monthNumber, $scope.year);
488507
setInputValue();
489-
};
508+
};
490509

491510
$scope.setNewYear = function setNewYear(year) {
492511

@@ -835,6 +854,9 @@
835854
$scope.$on('$destroy', function unregisterListener() {
836855

837856
unregisterDataSetWatcher();
857+
unregisterDateMinLimitWatcher();
858+
unregisterDateMaxLimitWatcher();
859+
unregisterDateFormatWatcher();
838860
thisInput.off('focus click focusout blur');
839861
angular.element(theCalendar).off('mouseenter mouseleave focusin');
840862
angular.element($window).off('click focus focusin', onClickOnWindow);

0 commit comments

Comments
 (0)