Moment datepicker input emitting old values of input text when invalid
Bug, feature request, or proposal:
Bug
What is the expected behavior?
ErrorStateMatcher.isErrorState should be passed the current value of the input text:
{ "matDatepickerParse": { "text": "foo" } }
What is the current behavior?
ErrorStateMatcher.isErrorState is passed control errors that contain old input values:
{ "matDatepickerParse": { "text": "" } }
What are the steps to reproduce?
Steps to reproduce:
- Visit https://angular-ypzjum.stackblitz.io/
- Type in an invalid value into the input (i.e. "foo")
- View console statements
What is the use-case or motivation for changing an existing behavior?
I would like to ignore parse values for empty date inputs so that I can ignore errors when dates are not required.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
See stackblitz dependencies. I have not tested with any other versions. Tested in Chrome Version 69.0.3497.100 (Official Build) (64-bit) and FireFox developer edition 63.0b11 (64-bit)
Is there anything else we should know?
Nope.
I will look into this more to try and find the actual cause.
@jelbourn I think this bug was introduced by #10952. If multiple consecutive inputs events are invalid, the datepicker input will not notify the control value accessor since the date has not changed (null === null). I think the control value accessor should always be notified of changes.
Thanks for looking into it, that makes sense
I am also running into this issue, If the first thing you type in the input is invalid date ("ab") the change event is never raised and the matDatepickerParse error is not set. I see there is a PR for this fix but it is not merged yet.
I believe thats it was fixed https://github.com/angular/components/issues/19613#issuecomment-1209822903. I recommend close this issue @andrewseguin
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.