|
24 | 24 | * @param {expression=} ng-change Expression evaluated when the model value changes. |
25 | 25 | * @param {expression=} ng-focus Expression evaluated when the input is focused or the calendar is opened. |
26 | 26 | * @param {expression=} ng-blur Expression evaluated when focus is removed from the input or the calendar is closed. |
| 27 | + * @param {boolean=} ng-disabled Whether the datepicker is disabled. |
| 28 | + * @param {boolean=} ng-required Whether a value is required for the datepicker. |
27 | 29 | * @param {Date=} md-min-date Expression representing a min date (inclusive). |
28 | 30 | * @param {Date=} md-max-date Expression representing a max date (inclusive). |
29 | 31 | * @param {(function(Date): boolean)=} md-date-filter Function expecting a date and returning a boolean whether it can be selected or not. |
|
36 | 38 | * * `"all"` - Hides all icons. |
37 | 39 | * * `"calendar"` - Only hides the calendar icon. |
38 | 40 | * * `"triangle"` - Only hides the triangle icon. |
39 | | - * @param {boolean=} ng-disabled Whether the datepicker is disabled. |
40 | | - * @param {boolean=} ng-required Whether a value is required for the datepicker. |
| 41 | + * @param {Object=} md-date-locale Allows for the values from the `$mdDateLocaleProvider` to be |
| 42 | + * ovewritten on a per-element basis (e.g. `msgOpenCalendar` can be overwritten with |
| 43 | + * `md-date-locale="{ msgOpenCalendar: 'Open a special calendar' }"`). |
41 | 44 | * |
42 | 45 | * @description |
43 | 46 | * `<md-datepicker>` is a component used to select a single date. |
|
79 | 82 | '<md-button type="button" md-no-ink ' + |
80 | 83 | 'class="md-datepicker-triangle-button md-icon-button" ' + |
81 | 84 | 'ng-click="ctrl.openCalendarPane($event)" ' + |
82 | | - 'aria-label="{{::ctrl.dateLocale.msgOpenCalendar}}">' + |
| 85 | + 'aria-label="{{::ctrl.locale.msgOpenCalendar}}">' + |
83 | 86 | '<div class="md-datepicker-expand-triangle"></div>' + |
84 | 87 | '</md-button>'; |
85 | 88 |
|
|
102 | 105 | '<div class="md-datepicker-input-mask-opaque"></div>' + |
103 | 106 | '</div>' + |
104 | 107 | '<div class="md-datepicker-calendar">' + |
105 | | - '<md-calendar role="dialog" aria-label="{{::ctrl.dateLocale.msgCalendar}}" ' + |
| 108 | + '<md-calendar role="dialog" aria-label="{{::ctrl.locale.msgCalendar}}" ' + |
106 | 109 | 'md-current-view="{{::ctrl.currentView}}"' + |
107 | 110 | 'md-min-date="ctrl.minDate"' + |
108 | 111 | 'md-max-date="ctrl.maxDate"' + |
|
120 | 123 | currentView: '@mdCurrentView', |
121 | 124 | dateFilter: '=mdDateFilter', |
122 | 125 | isOpen: '=?mdIsOpen', |
123 | | - debounceInterval: '=mdDebounceInterval' |
| 126 | + debounceInterval: '=mdDebounceInterval', |
| 127 | + dateLocale: '=mdDateLocale' |
124 | 128 | }, |
125 | 129 | controller: DatePickerCtrl, |
126 | 130 | controllerAs: 'ctrl', |
|
232 | 236 | /** @final */ |
233 | 237 | this.$window = $window; |
234 | 238 |
|
235 | | - /** @final */ |
236 | | - this.dateLocale = $mdDateLocale; |
237 | | - |
238 | 239 | /** @final */ |
239 | 240 | this.dateUtil = $$mdDateUtil; |
240 | 241 |
|
|
247 | 248 | /** @final */ |
248 | 249 | this.$$rAF = $$rAF; |
249 | 250 |
|
| 251 | + /** |
| 252 | + * Holds locale-specific formatters, parsers, labels etc. Allows |
| 253 | + * the user to override specific ones from the $mdDateLocale provider. |
| 254 | + * @type {!Object} |
| 255 | + */ |
| 256 | + this.locale = this.dateLocale ? angular.extend({}, $mdDateLocale, this.dateLocale) : $mdDateLocale; |
| 257 | + |
250 | 258 | /** |
251 | 259 | * The root document element. This is used for attaching a top-level click handler to |
252 | 260 | * close the calendar panel when a click outside said panel occurs. We use `documentElement` |
|
585 | 593 | */ |
586 | 594 | DatePickerCtrl.prototype.handleInputEvent = function() { |
587 | 595 | var inputString = this.inputElement.value; |
588 | | - var parsedDate = inputString ? this.dateLocale.parseDate(inputString) : null; |
| 596 | + var parsedDate = inputString ? this.locale.parseDate(inputString) : null; |
589 | 597 | this.dateUtil.setDateTimeToMidnight(parsedDate); |
590 | 598 |
|
591 | 599 | // An input string is valid if it is either empty (representing no date) |
592 | 600 | // or if it parses to a valid date that the user is allowed to select. |
593 | 601 | var isValidInput = inputString == '' || ( |
594 | 602 | this.dateUtil.isValidDate(parsedDate) && |
595 | | - this.dateLocale.isDateComplete(inputString) && |
| 603 | + this.locale.isDateComplete(inputString) && |
596 | 604 | this.isDateEnabled(parsedDate) |
597 | 605 | ); |
598 | 606 |
|
|
869 | 877 | var timezone = this.$mdUtil.getModelOption(this.ngModelCtrl, 'timezone'); |
870 | 878 |
|
871 | 879 | this.date = value; |
872 | | - this.inputElement.value = this.dateLocale.formatDate(value, timezone); |
| 880 | + this.inputElement.value = this.locale.formatDate(value, timezone); |
873 | 881 | this.mdInputContainer && this.mdInputContainer.setHasValue(!!value); |
874 | 882 | this.closeCalendarPane(); |
875 | 883 | this.resizeInputElement(); |
|
0 commit comments