@@ -34,6 +34,7 @@ import {
34
34
import { DateAdapter , MD_DATE_FORMATS , MdDateFormats } from '@angular/material/core' ;
35
35
import { MdFormField } from '@angular/material/form-field' ;
36
36
import { Subscription } from 'rxjs/Subscription' ;
37
+ import { coerceDateProperty } from './coerce-date-property' ;
37
38
import { MdDatepicker } from './datepicker' ;
38
39
import { createMissingDateImplError } from './datepicker-errors' ;
39
40
@@ -74,8 +75,8 @@ export class MdDatepickerInputEvent<D> {
74
75
host : {
75
76
'[attr.aria-haspopup]' : 'true' ,
76
77
'[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' ,
79
80
'[disabled]' : 'disabled' ,
80
81
'(input)' : '_onInput($event.target.value)' ,
81
82
'(change)' : '_onChange()' ,
@@ -122,9 +123,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
122
123
return this . _value ;
123
124
}
124
125
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 ) ;
128
127
this . _lastValueValid = ! value || this . _dateAdapter . isValid ( value ) ;
129
128
value = this . _getValidDateOrNull ( value ) ;
130
129
@@ -142,7 +141,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
142
141
@Input ( )
143
142
get min ( ) : D | null { return this . _min ; }
144
143
set min ( value : D | null ) {
145
- this . _min = value ;
144
+ this . _min = coerceDateProperty ( this . _dateAdapter , value ) ;
146
145
this . _validatorOnChange ( ) ;
147
146
}
148
147
private _min : D | null ;
@@ -151,7 +150,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
151
150
@Input ( )
152
151
get max ( ) : D | null { return this . _max ; }
153
152
set max ( value : D | null ) {
154
- this . _max = value ;
153
+ this . _max = coerceDateProperty ( this . _dateAdapter , value ) ;
155
154
this . _validatorOnChange ( ) ;
156
155
}
157
156
private _max : D | null ;
@@ -199,21 +198,24 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
199
198
200
199
/** The form control validator for the min date. */
201
200
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 } } ;
205
205
}
206
206
207
207
/** The form control validator for the max date. */
208
208
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 } } ;
212
213
}
213
214
214
215
/** The form control validator for the date filter. */
215
216
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 ) ?
217
219
null : { 'mdDatepickerFilter' : true } ;
218
220
}
219
221
0 commit comments