angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.35k stars 6.74k forks source link

Datepicker set value updates text even if value doesn't change #6333

Open james-schwartzkopf opened 7 years ago

james-schwartzkopf commented 7 years ago

Bug, feature request, or proposal:

What is the expected behavior?

Only update the input text if the value passed to the setter has changed.

What is the current behavior?

The text of the input is always set to the formatted version of the value.

What are the steps to reproduce?

http://plnkr.co/edit/kaS3PvvuSmn0leykKy2D?p=preview

Try to enter a date by typing (typing a '0' will instantly change to 1/1/2000

What is the use-case or motivation for changing an existing behavior?

The plunker above implements what I understand to be a common pattern with using ngrx/store with reactive forms.

The FormGroup valueChanges emitter is used to keep the store updated with the users changes.

FormGroup setValue is used to keep the form synced with the store (so changes in the store besides those created by valueChanges will be also be reflected in the form).

I think this could be fixed by moving the renderer.setProperty call to inside the sameDate check in the MdDatepickerInput value property setter.

If so, it would probably also make sense to add some code to the blur event to format and set the inputs text so the value displayed in the input after the user leaves the field is the canonical form of the date (zero padding, separators, etc).

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

beta-8

Is there anything else we should know?

mmalerba commented 6 years ago

updated plunker: http://plnkr.co/edit/qQtXaX5uIGIgLZrq8QA6?p=preview

mark-langer commented 6 years ago

Hi @mmalerba even the updated Plunk from November generates an error. Just letting you know.