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

Commit 08ed0e3

Browse files
committed
Added date-enabled-dates as an option similar to date-disabled-dates.
1 parent 662d9b1 commit 08ed0e3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
bower_components/
33
npm-debug.log
4+
**/.idea

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ date-format="" | String | String(new Date()) | Set the date format you want to u
8585
date-min-limit="" | String | false | Set a minimum date limit - you can use all the accepted date formats by the javascript `new Date()`
8686
date-max-limit="" | String | false | Set a maximum date limit - you can use all the accepted date formats by the javascript `new Date()`
8787
date-set-hidden="" | String(Boolean) | false | Set the default date to be shown only in calendar and not in the input field
88-
date-disabled-dates="" | String([Date(), Date(), ...]) | false | Disable specific dates using an _Array_ of dates
88+
date-disabled-dates="" | String([Date(), Date(), ...]) | false | Disable specific dates using an _Array_ of dates.
89+
date-enabled-dates="" | String([Date(), Date(), ...]) | false | Enable only the specific dates using an _Array_ of dates.
8990
date-disabled-weekdays="" | String(1, 5, ...]) | false | Disable specific weekdays using an _Array_ of weeks number
9091
date-refocus="" | String(Boolean) | false | Set the datepicker to re-focus the input after selecting a date
9192
date-typer="" | String(Boolean) | false | Set the datepicker to update calendar date when user is typing a date, see validation [tips](#date-validation)

src/js/angular-datepicker.js

+29
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
//, dateMinLimit
158158
//, dateMaxLimit
159159
, dateDisabledDates = $scope.$eval($scope.dateDisabledDates)
160+
, dateEnabledDates = $scope.$eval($scope.dateEnabledDates)
160161
, dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays)
161162
, date = new Date()
162163
, isMouseOn = false
@@ -483,6 +484,17 @@
483484
if (newValue) {
484485
dateDisabledDates = $scope.$eval(newValue);
485486

487+
if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) {
488+
thisInput.val('');
489+
thisInput.triggerHandler('input');
490+
thisInput.triggerHandler('change');//just to be sure;
491+
}
492+
}
493+
})
494+
, unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) {
495+
if (newValue) {
496+
dateEnabledDates = $scope.$eval(newValue);
497+
486498
if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) {
487499
thisInput.val('');
488500
thisInput.triggerHandler('input');
@@ -788,6 +800,21 @@
788800
}
789801
}
790802
}
803+
804+
if (dateEnabledDates &&
805+
dateEnabledDates.length > 0) {
806+
807+
for (i; i <= dateEnabledDates.length; i += 1) {
808+
809+
if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
810+
811+
return true;
812+
}
813+
}
814+
815+
return false;
816+
}
817+
791818
return true;
792819
};
793820

@@ -973,6 +1000,7 @@
9731000
unregisterDateMaxLimitWatcher();
9741001
unregisterDateFormatWatcher();
9751002
unregisterDateDisabledDatesWatcher();
1003+
unregisterDateEnabledDatesWatcher();
9761004
thisInput.off('focus click focusout blur');
9771005
angular.element(theCalendar).off('mouseenter mouseleave focusin');
9781006
angular.element($window).off('click focus focusin', onClickOnWindow);
@@ -990,6 +1018,7 @@
9901018
'buttonNextTitle': '@',
9911019
'buttonPrevTitle': '@',
9921020
'dateDisabledDates': '@',
1021+
'dateEnabledDates': '@',
9931022
'dateDisabledWeekdays': '@',
9941023
'dateSetHidden': '@',
9951024
'dateTyper': '@',

0 commit comments

Comments
 (0)