@@ -119,6 +119,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
119119 if ( value != null && ! this . _dateAdapter . isDateInstance ( value ) ) {
120120 throw Error ( 'Datepicker: value not recognized as a date object by DateAdapter.' ) ;
121121 }
122+ this . _lastValueValid = ! value || this . _dateAdapter . isValid ( value ) ;
122123 value = this . _getValidDateOrNull ( value ) ;
123124
124125 let oldDate = this . value ;
@@ -133,7 +134,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
133134 @Input ( )
134135 get min ( ) : D | null { return this . _min ; }
135136 set min ( value : D | null ) {
136- this . _min = this . _getValidDateOrNull ( value ) ;
137+ this . _min = value ;
137138 this . _validatorOnChange ( ) ;
138139 }
139140 private _min : D | null ;
@@ -142,7 +143,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
142143 @Input ( )
143144 get max ( ) : D | null { return this . _max ; }
144145 set max ( value : D | null ) {
145- this . _max = this . _getValidDateOrNull ( value ) ;
146+ this . _max = value ;
146147 this . _validatorOnChange ( ) ;
147148 }
148149 private _max : D | null ;
@@ -173,9 +174,9 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
173174 private _datepickerSubscription : Subscription ;
174175
175176 /** 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 } } ;
179180 }
180181
181182 /** The form control validator for the min date. */
@@ -203,6 +204,9 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
203204 Validators . compose (
204205 [ this . _parseValidator , this . _minValidator , this . _maxValidator , this . _filterValidator ] ) ;
205206
207+ /** Whether the last value set on the input was valid. */
208+ private _lastValueValid = false ;
209+
206210 constructor (
207211 private _elementRef : ElementRef ,
208212 private _renderer : Renderer2 ,
@@ -280,6 +284,8 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
280284
281285 _onInput ( value : string ) {
282286 let date = this . _dateAdapter . parse ( value , this . _dateFormats . parse . dateInput ) ;
287+ this . _lastValueValid = ! date || this . _dateAdapter . isValid ( date ) ;
288+ date = this . _getValidDateOrNull ( date ) ;
283289 this . _cvaOnChange ( date ) ;
284290 this . _valueChange . emit ( date ) ;
285291 this . dateInput . emit ( new MdDatepickerInputEvent ( this , this . _elementRef . nativeElement ) ) ;
0 commit comments