-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datepicker works only for en locale #7143
Comments
I was just going to open an issue for the same thing but with es-ES locale. Example: We are in september so you select the 2nd of september, it will result in 02/09/2017 in es-ES locale. If you reopen the calendar you will find that it is focused on february because it takes the first number to get the month. Another problem i have changing the locale is that when i put a ngModel to the input and i set it to null through code the input is cleaned but the calendar dont and i can't reselect the same date because it is already selected. I provide a plunker with the example. In it you can see both of my problems. The LOCALE_ID is set to "es-ES" in the NgModule. In order to reproduce the errors yo can follow this steps:
In you do this with "en" locale no one of the previous bugs happen. It is expected for the calendar to work even when the locale is changed. Plunker: https://plnkr.co/edit/lBexYUJOFSNWJszXIfTF?p=preview |
I would add third problem |
You need to build a custom date adapter with an apropriate |
but your solution doesn't work for any other locales, what's the point of your documentation section 'Setting the locale code' https://material.angular.io/components/datepicker/overview#setting-the-locale-code if it doesn't work properly and user can't fill in his locale date format? |
@Viktor-Bredihin, the reason it works like this is explained in the bottom of the section you pointed out:
The team is in the final stages of the MomentDateAdapter that is supposed to be more suitable to define formats. |
@julianobrasil your are right, sorry. And your solution works for me, thank you very much |
it's broken after update, the error is 'Datepicker: value not recognized as a date object by DateAdapter', parse function didn't call |
I finally got it working by creating my own date adapter for moment, i leave it here in case it works for you too:
|
@Viktor-Bredihin, how are you trying to set Datepicker value? From beta.10 on it must be a Date object (before, it could be a string). |
I'm trying to set up string, right |
I get it from backend |
is there any way to get it works with strings? I can't parse it each time from backend and transform to date object |
before you can use it with Datepicker, you have to turn it in a Date object (alternatively, you can build your own CustomDateAdapter from scratch) |
Take a look at here: #7167 (comment) It helps if you decide to build your own Date Adapter. |
@julianobrasil thanks, but for now I will just use datehelper for all my models to transform backend date to js date |
Closing as using a dd.mm.yyyy format will require a custom date adapter. The momentjs adapter should allow for this usage. |
I have seen the moment adapter in the feature section on the Changelog, but i didn't find any documentation on how to set this adapter for the use. @josephperrott can you explain how i can import it and use it or give some reference to a documentation that indicates how to do it? For the moment i am using my date adapter posted here, I have tried to import the new adapter but it always says that 'angular/material' has no exported member named 'MomentDateModule', 'MdMomentDateModule', 'MomentDateAdapter', 'MdMomentDateAdapter' or similar... (I don't know how many names i have tried.. XD) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
when you check datepicker from German locale, you can see the right representation of the date, also if you select date using datepicker - works fine. But when you fill in date manually (german format dd.mm.YYYY) it's considered as invalid and expecting mm.dd.YYYY
What is the expected behavior?
when my locale is different to en, I'm expecting not only representation to be changed, but also validation logic
What is the current behavior?
You can't fill in date manually in your local format
What are the steps to reproduce?
Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: https://goo.gl/DlHd6U
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Is there anything else we should know?
The text was updated successfully, but these errors were encountered: