components icon indicating copy to clipboard operation
components copied to clipboard

Moment datepicker input emitting old values of input text when invalid

Open alexluecke opened this issue 8 years ago • 6 comments

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:

  1. Visit https://angular-ypzjum.stackblitz.io/
  2. Type in an invalid value into the input (i.e. "foo")
  3. 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.

alexluecke avatar Oct 03 '18 17:10 alexluecke

I will look into this more to try and find the actual cause.

alexluecke avatar Oct 03 '18 17:10 alexluecke

@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.

alexluecke avatar Oct 06 '18 23:10 alexluecke

Thanks for looking into it, that makes sense

jelbourn avatar Oct 08 '18 16:10 jelbourn

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.

vikasm-mittal avatar Oct 09 '18 18:10 vikasm-mittal

I believe thats it was fixed https://github.com/angular/components/issues/19613#issuecomment-1209822903. I recommend close this issue @andrewseguin

viniciusschuelter avatar Aug 13 '22 17:08 viniciusschuelter

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.