components: DatePicker with MAT_DATE_LOCALE = en-GB parses incorrectly if the day is changed?
Bug:
With DatePicker, in the NgModule, I have the following settings:
providers: [{ provide: MAT_DATE_LOCALE, useValue: 'en-GB' },
{ provide: LOCALE_ID, useValue: "en-GB" },
If I input a string like “10/12/2017”, the picker will has 12 Oct 2017 selected, instead of 10 Dec 2017 since en-GB should use DD/MM/YYYY.
Others features of the DatePicker are working fine.
What are the steps to reproduce?
In the plnkr example provided at https://material.angular.io/components/datepicker/overview, in main.ts, just add settings to NgModule:
providers: [{ provide: MAT_DATE_LOCALE, useValue: 'en-GB' },
{ provide: LOCALE_ID, useValue: "en-GB" },
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 4.4.4, Material: Beta 12.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 16 (2 by maintainers)
+1 as Iuqeckr
I changed this moment date adapter a bit. This works for me:
And don’t forget to update main application module with providers:
I made some changes and it works for me now 😃 :
import 'moment/locale/fr';
{ provide: MAT_DATE_LOCALE, useValue: 'fr-FR' }, { provide: MAT_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS }, { provide: DateAdapter, useClass: MomentDateAdapter },
and of course import those variables withimport { MomentDateAdapter, MOMENT_DATE_FORMATS } from './moment-date-adapter';
Stackblitz example : https://stackblitz.com/edit/angular-date-picker-sample-fr
i would like to see a fix to that please
The official material one is also published to npm now: https://www.npmjs.com/package/@angular/material-moment-adapter. Second to last example on the datepicker examples page shows it in action: https://material.angular.io/components/datepicker/examples
+1 same problem
you don’t have to include both MAT_DATE_LOCALE and LOCALE_ID
i also use dd/mm/yyyy format (id-ID locale) and has the same problem but the date picker toggle give me DD/MM/YYYY and it’s valid
when i try to type manually in the input element the format in input element still use MM/DD/YYYY
so 24/7/2017 give me invalid status, when typing manually but valid status when picking from the picker button.
fix is here:
https://material.angular.io/components/datepicker/overview#setting-the-locale-code
https://stackblitz.com/angular/brljkagkoxaj?file=app%2Fdatepicker-locale-example.ts
I have the same issue as well. I wrote a custom adapter for it as well. When picking from the calendar, the date is valid, but entering the date manually makes it invalid
@NaifousBS sorry, I have no time right now, but I’ll try to do that ASAP.