components icon indicating copy to clipboard operation
components copied to clipboard

Md-Datepicker popup is not reseting after deleting the input field with code

Open Leonzen opened this issue 9 years ago • 7 comments

Bug, feature request, or proposal:

Bug and feature request

What is the expected behavior?

If the value of an input field, which is bound to a datepicker, is set to "" with typescript-code and not by clearing it with the keyboard, the datepicker-popup should be reseted.

What is the current behavior?

By setting the input field to "" with typescript code, the datepicker-popup is still on the date which was selected befor.

What are the steps to reproduce?

https://embed.plnkr.co/RPiSbw5XTJSqs8WHHE9M/

I have made a delete button to delete the date, because I have disabled the input field. By clicking the "X"-Button the date will be deleted but the selected date at the datepicker-popup is still there.

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

This should prevent the user of typing an invalid date format by forcing him/her to choose the date with the popup. To provide the function of deleting the date (for example: a date was picked by an incident), a button with an delete function should be provided.

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

Angular: 4.2.4 Material: 2.0.0-beta.7 OS: Windows 10 TypeScript: 2.3.4 Browser: Chrome 59.0.3071.115 and Firefox 52.2.1 (but probably all browsers)

Is there anything else we should know?

And by the way: there is still the problem of displaying the wrong month after selecting a date, because the day of the date will be used as month for the next selection.

Leonzen avatar Jul 03 '17 13:07 Leonzen

I'm afraid it's not clear why you're trying to manually set the value of the input instead of using Angular bindings. Or why you are trying to bind [value] with void?

As you can see here, there is no issue

https://plnkr.co/edit/BQ8qNgMKXlTHAWV01DMs?p=preview

willshowell avatar Jul 03 '17 13:07 willshowell

Ok, I didn't know that it can be solved like this. Issue solved :)

Leonzen avatar Jul 03 '17 14:07 Leonzen

It looked like it was working, but if you select a date with a day bigger then 12 it is not resetting.

Leonzen avatar Jul 04 '17 06:07 Leonzen

@Leonzen seems to be working fine in the example provided by @crisbeto, if I choose 12/31/2017 and then press the x it resets

mmalerba avatar Jul 05 '17 21:07 mmalerba

@mmalerba I think my problem is, that I am in germany and the datepicker is using the american standard. Could you tell me how to set the german date fromat?

Leonzen avatar Jul 06 '17 06:07 Leonzen

Ah, so the issue here is that the NativeDateAdapter uses JavaScript's native Date object to do date parsing. Unfortunately the Date object always parses things the american way. Currently to get around this you have to write a custom DateAdapter that either uses some date library or implements custom parsing logic. We know this is not ideal and we plan to create a MomentDateAdapter that will use Moment.js for parsing and formatting to make this easier for developers willing to use Moment.js

The internationalization section of the datepicker docs talks about some of this: https://material.angular.io/components/datepicker/overview

And the NativeDateAdapter is a good example to follow when creating your own DateAdapter (you could even just extend it and override the parsing behavior): https://github.com/angular/material2/blob/master/src/lib/core/datetime/native-date-adapter.ts

mmalerba avatar Jul 06 '17 16:07 mmalerba

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.