|
24 | 24 | * @param {expression=} ng-change Expression evaluated when the model value changes.
|
25 | 25 | * @param {Date=} md-min-date Expression representing a min date (inclusive).
|
26 | 26 | * @param {Date=} md-max-date Expression representing a max date (inclusive).
|
| 27 | + * @param {(function(Date): boolean)=} md-date-filter Function expecting a date and returning a boolean whether it can be selected or not. |
27 | 28 | * @param {boolean=} disabled Whether the datepicker is disabled.
|
28 | 29 | * @param {boolean=} required Whether a value is required for the datepicker.
|
29 | 30 | *
|
|
75 | 76 | '<div class="md-datepicker-calendar">' +
|
76 | 77 | '<md-calendar role="dialog" aria-label="{{::ctrl.dateLocale.msgCalendar}}" ' +
|
77 | 78 | 'md-min-date="ctrl.minDate" md-max-date="ctrl.maxDate"' +
|
| 79 | + 'md-date-filter="ctrl.dateFilter"' + |
78 | 80 | 'ng-model="ctrl.date" ng-if="ctrl.isCalendarOpen">' +
|
79 | 81 | '</md-calendar>' +
|
80 | 82 | '</div>' +
|
|
83 | 85 | scope: {
|
84 | 86 | minDate: '=mdMinDate',
|
85 | 87 | maxDate: '=mdMaxDate',
|
86 |
| - placeholder: '@mdPlaceholder' |
| 88 | + placeholder: '@mdPlaceholder', |
| 89 | + dateFilter: '=mdDateFilter' |
87 | 90 | },
|
88 | 91 | controller: DatePickerCtrl,
|
89 | 92 | controllerAs: 'ctrl',
|
|
356 | 359 | if (this.dateUtil.isValidDate(this.maxDate)) {
|
357 | 360 | this.ngModelCtrl.$setValidity('maxdate', this.date <= this.maxDate);
|
358 | 361 | }
|
| 362 | + |
| 363 | + if (angular.isFunction(this.dateFilter)) { |
| 364 | + this.ngModelCtrl.$setValidity('filtered', this.dateFilter(this.date)); |
| 365 | + } |
359 | 366 | }
|
360 | 367 | };
|
361 | 368 |
|
|
377 | 384 | this.date = null;
|
378 | 385 | this.inputContainer.classList.remove(INVALID_CLASS);
|
379 | 386 | } else if (this.dateUtil.isValidDate(parsedDate) &&
|
380 |
| - this.dateLocale.isDateComplete(inputString) && |
381 |
| - this.dateUtil.isDateWithinRange(parsedDate, this.minDate, this.maxDate)) { |
| 387 | + this.dateLocale.isDateComplete(inputString) && |
| 388 | + this.isDateEnabled(parsedDate)) { |
382 | 389 | this.ngModelCtrl.$setViewValue(parsedDate);
|
383 | 390 | this.date = parsedDate;
|
384 | 391 | this.inputContainer.classList.remove(INVALID_CLASS);
|
|
387 | 394 | this.inputContainer.classList.toggle(INVALID_CLASS, inputString);
|
388 | 395 | }
|
389 | 396 | };
|
390 |
| - |
| 397 | + |
| 398 | + /** |
| 399 | + * Check whether date is in range and enabled |
| 400 | + * @param {Date=} opt_date |
| 401 | + * @return {boolean} Whether the date is enabled. |
| 402 | + */ |
| 403 | + DatePickerCtrl.prototype.isDateEnabled = function(opt_date) { |
| 404 | + return this.dateUtil.isDateWithinRange(opt_date, this.minDate, this.maxDate) && |
| 405 | + (!angular.isFunction(this.dateFilter) || this.dateFilter(opt_date)); |
| 406 | + } |
| 407 | + |
391 | 408 | /** Position and attach the floating calendar to the document. */
|
392 | 409 | DatePickerCtrl.prototype.attachCalendarPane = function() {
|
393 | 410 | var calendarPane = this.calendarPane;
|
|
0 commit comments