Skip to content
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

Datepickers do not allow to type dates when nzFormat is different than default #5654

Closed
valerio-lucantonio opened this issue Aug 7, 2020 · 8 comments
Assignees
Labels
Milestone

Comments

@valerio-lucantonio
Copy link

Reproduction link

https://stackblitz.com/edit/angular-dnrngb

Steps to reproduce

  1. set a custom nzFormat (like dd.MM.yyyy)
  2. try to type a date manually

What is expected?

to be able to write dates according to the nzFormat

What is actually happening?

nothing happens. The date are not modified

Environment Info
ng-zorro-antd 9.3.0
Browser chrome

would be cool on tab out to close the flyout as well

@wenqi73
Copy link
Member

wenqi73 commented Aug 7, 2020

@wenqi73
Copy link
Member

wenqi73 commented Aug 7, 2020

We should add this in document. 🤔

@wenqi73 wenqi73 added 📜 Doc ❓ FAQ Frequently asked questions. labels Aug 7, 2020
@valerio-lucantonio
Copy link
Author

It works indeed, thank you very much!

@MoritzNeugebauer
Copy link

It works indeed, thank you very much!

@valerio-lucantonio what exactly did you do to make it work?

In app.module.ts I import

import de from '@angular/common/locales/de';
import { registerLocaleData } from '@angular/common';
import { NZ_I18N, de_DE, NzModalModule, NzNotificationModule, NZ_DATE_LOCALE } from 'ng-zorro-antd';
registerLocaleData(de);

and set providers like this:
{ provide: NZ_I18N, useValue: de_DE },
{ provide: NZ_DATE_LOCALE, useValue: de_DE },

In my component I use dateRangePicker:
<nz-range-picker
[ngModel]="selectedKatalogwert.datumVonRange"
(ngModelChange)="updateFilterModel($event,ka)"
nzFormat="yyyyMMdd"
[ngModelOptions]="{ updateOn: 'blur' }"
(keydown.enter)="$event.target.blur()">

When clicking on the RangePicker to select a Date it throws an error:
core.js:6241 ERROR RangeError: locale must contain localize property
at format (index.js:361)
at DateHelperByDateFns.format (ng-zorro-antd-i18n.js:1069)
at DateTableComponent.makeHeadRow (ng-zorro-antd-date-picker.js:4796)
at DateTableComponent.render (ng-zorro-antd-date-picker.js:4587)
at DateTableComponent.ngOnInit (ng-zorro-antd-date-picker.js:4612)
at callHook (core.js:4726)
at callHooks (core.js:4690)
at executeInitAndCheckHooks (core.js:4630)
at refreshView (core.js:12026)
at refreshEmbeddedViews (core.js:13404)

@wenqi73
Copy link
Member

wenqi73 commented Oct 30, 2020

The value of NZ_DATE_LOCALE is from 'date-fns', not ng-zorro.

@wenqi73 wenqi73 closed this as completed Oct 30, 2020
@MoritzNeugebauer
Copy link

I overlooked the comment
// Set the value of NZ_DATE_LOCALE in the application root module to activate date-fns mode

So I manually set the value NZ_DATE_LOCALE in my app.module.ts like this
import { de as german } from 'date-fns/locale';
const NZ_DATE_LOCALE = german;

so that I can use it as a provider:
{ provide: NZ_DATE_LOCALE, useValue: de_DE },

Is this the way I should do it? It removed the error, but still DateRangePicker doesn't allow to type dates when I set nzFormat="yyyyMMdd"

@MoritzNeugebauer
Copy link

Sorry, this is odd. Now I got it working:

import { NZ_I18N, NzModalModule, NzNotificationModule, NZ_DATE_LOCALE } from 'ng-zorro-antd';
import deDateLocale from 'date-fns/locale/de';

{ provide: NZ_DATE_LOCALE, useValue: deDateLocale },

Thank you very much for your support, @wenqi73

@asamirel
Copy link

asamirel commented Apr 8, 2021

when i try to import deDateLocale from 'date-fns/locale/de', it gives me error :
Module '"date-fns/locale/de"' has no default export
does anyone knows how to pass this error ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants