@@ -34,6 +34,7 @@ import {
3434import { DateAdapter , MD_DATE_FORMATS , MdDateFormats } from '@angular/material/core' ;
3535import { MdFormField } from '@angular/material/form-field' ;
3636import { Subscription } from 'rxjs/Subscription' ;
37+ import { coerceDateProperty } from './coerce-date-property' ;
3738import { MdDatepicker } from './datepicker' ;
3839import { createMissingDateImplError } from './datepicker-errors' ;
3940
@@ -74,8 +75,8 @@ export class MdDatepickerInputEvent<D> {
7475 host : {
7576 '[attr.aria-haspopup]' : 'true' ,
7677 '[attr.aria-owns]' : '(_datepicker?.opened && _datepicker.id) || null' ,
77- '[attr.min]' : 'min ? _dateAdapter.getISODateString (min) : null' ,
78- '[attr.max]' : 'max ? _dateAdapter.getISODateString (max) : null' ,
78+ '[attr.min]' : 'min ? _dateAdapter.toIso8601 (min) : null' ,
79+ '[attr.max]' : 'max ? _dateAdapter.toIso8601 (max) : null' ,
7980 '[disabled]' : 'disabled' ,
8081 '(input)' : '_onInput($event.target.value)' ,
8182 '(change)' : '_onChange()' ,
@@ -122,9 +123,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
122123 return this . _value ;
123124 }
124125 set value ( value : D | null ) {
125- if ( value != null && ! this . _dateAdapter . isDateInstance ( value ) ) {
126- throw Error ( 'Datepicker: value not recognized as a date object by DateAdapter.' ) ;
127- }
126+ value = coerceDateProperty ( this . _dateAdapter , value ) ;
128127 this . _lastValueValid = ! value || this . _dateAdapter . isValid ( value ) ;
129128 value = this . _getValidDateOrNull ( value ) ;
130129
@@ -142,7 +141,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
142141 @Input ( )
143142 get min ( ) : D | null { return this . _min ; }
144143 set min ( value : D | null ) {
145- this . _min = value ;
144+ this . _min = coerceDateProperty ( this . _dateAdapter , value ) ;
146145 this . _validatorOnChange ( ) ;
147146 }
148147 private _min : D | null ;
@@ -151,7 +150,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
151150 @Input ( )
152151 get max ( ) : D | null { return this . _max ; }
153152 set max ( value : D | null ) {
154- this . _max = value ;
153+ this . _max = coerceDateProperty ( this . _dateAdapter , value ) ;
155154 this . _validatorOnChange ( ) ;
156155 }
157156 private _max : D | null ;
@@ -199,21 +198,24 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
199198
200199 /** The form control validator for the min date. */
201200 private _minValidator : ValidatorFn = ( control : AbstractControl ) : ValidationErrors | null => {
202- return ( ! this . min || ! control . value ||
203- this . _dateAdapter . compareDate ( this . min , control . value ) <= 0 ) ?
204- null : { 'mdDatepickerMin' : { 'min' : this . min , 'actual' : control . value } } ;
201+ const controlValue = coerceDateProperty ( this . _dateAdapter , control . value ) ;
202+ return ( ! this . min || ! controlValue ||
203+ this . _dateAdapter . compareDate ( this . min , controlValue ) <= 0 ) ?
204+ null : { 'mdDatepickerMin' : { 'min' : this . min , 'actual' : controlValue } } ;
205205 }
206206
207207 /** The form control validator for the max date. */
208208 private _maxValidator : ValidatorFn = ( control : AbstractControl ) : ValidationErrors | null => {
209- return ( ! this . max || ! control . value ||
210- this . _dateAdapter . compareDate ( this . max , control . value ) >= 0 ) ?
211- null : { 'mdDatepickerMax' : { 'max' : this . max , 'actual' : control . value } } ;
209+ const controlValue = coerceDateProperty ( this . _dateAdapter , control . value ) ;
210+ return ( ! this . max || ! controlValue ||
211+ this . _dateAdapter . compareDate ( this . max , controlValue ) >= 0 ) ?
212+ null : { 'mdDatepickerMax' : { 'max' : this . max , 'actual' : controlValue } } ;
212213 }
213214
214215 /** The form control validator for the date filter. */
215216 private _filterValidator : ValidatorFn = ( control : AbstractControl ) : ValidationErrors | null => {
216- return ! this . _dateFilter || ! control . value || this . _dateFilter ( control . value ) ?
217+ const controlValue = coerceDateProperty ( this . _dateAdapter , control . value ) ;
218+ return ! this . _dateFilter || ! controlValue || this . _dateFilter ( controlValue ) ?
217219 null : { 'mdDatepickerFilter' : true } ;
218220 }
219221
0 commit comments