@@ -119,6 +119,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
119
119
if ( value != null && ! this . _dateAdapter . isDateInstance ( value ) ) {
120
120
throw Error ( 'Datepicker: value not recognized as a date object by DateAdapter.' ) ;
121
121
}
122
+ this . _lastValueValid = ! value || this . _dateAdapter . isValid ( value ) ;
122
123
value = this . _getValidDateOrNull ( value ) ;
123
124
124
125
let oldDate = this . value ;
@@ -133,7 +134,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
133
134
@Input ( )
134
135
get min ( ) : D | null { return this . _min ; }
135
136
set min ( value : D | null ) {
136
- this . _min = this . _getValidDateOrNull ( value ) ;
137
+ this . _min = value ;
137
138
this . _validatorOnChange ( ) ;
138
139
}
139
140
private _min : D | null ;
@@ -142,7 +143,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
142
143
@Input ( )
143
144
get max ( ) : D | null { return this . _max ; }
144
145
set max ( value : D | null ) {
145
- this . _max = this . _getValidDateOrNull ( value ) ;
146
+ this . _max = value ;
146
147
this . _validatorOnChange ( ) ;
147
148
}
148
149
private _max : D | null ;
@@ -173,9 +174,9 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
173
174
private _datepickerSubscription : Subscription ;
174
175
175
176
/** The form control validator for whether the input parses. */
176
- private _parseValidator : ValidatorFn = ( control : AbstractControl ) : ValidationErrors | null => {
177
- return ( ! control . value || this . _dateAdapter . isValid ( control . value ) ) ?
178
- null : { 'mdDatepickerParse' : true } ;
177
+ private _parseValidator : ValidatorFn = ( ) : ValidationErrors | null => {
178
+ return this . _lastValueValid ?
179
+ null : { 'mdDatepickerParse' : { 'text' : this . _elementRef . nativeElement . value } } ;
179
180
}
180
181
181
182
/** The form control validator for the min date. */
@@ -203,6 +204,9 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
203
204
Validators . compose (
204
205
[ this . _parseValidator , this . _minValidator , this . _maxValidator , this . _filterValidator ] ) ;
205
206
207
+ /** Whether the last value set on the input was valid. */
208
+ private _lastValueValid = false ;
209
+
206
210
constructor (
207
211
private _elementRef : ElementRef ,
208
212
private _renderer : Renderer2 ,
@@ -280,6 +284,8 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
280
284
281
285
_onInput ( value : string ) {
282
286
let date = this . _dateAdapter . parse ( value , this . _dateFormats . parse . dateInput ) ;
287
+ this . _lastValueValid = ! date || this . _dateAdapter . isValid ( date ) ;
288
+ date = this . _getValidDateOrNull ( date ) ;
283
289
this . _cvaOnChange ( date ) ;
284
290
this . _valueChange . emit ( date ) ;
285
291
this . dateInput . emit ( new MdDatepickerInputEvent ( this , this . _elementRef . nativeElement ) ) ;
0 commit comments