primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Date in p-calendar doesn't update when date format changes

Open Prontsevich opened this issue 9 years ago • 11 comments

I'm submitting a ...

[x ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)

http://plnkr.co/edit/U1mypT4F5N91l0vgKCl0

Current behavior Date in p-calendar doesn't update when date format changes.

Expected behavior Date in input field updates when date format changes.

What is the motivation / use case for changing the behavior? My app has several locations and date format depends on the selected locale. I want that date in the input field changes according to the selected locale.

  • PrimeNG version: 1.1.1
  • Browser: all

Prontsevich avatar Dec 28 '16 15:12 Prontsevich

Have the same problem in PrimeNG 4 :(

Prontsevich avatar May 03 '17 14:05 Prontsevich

What is the use case to change the dateformat dynamically? We don't check for it since I think it is not very common.

cagataycivici avatar Jun 19 '17 11:06 cagataycivici

We have several languages in our app and user can switch between them. And we use local date format for each language

Prontsevich avatar Jun 20 '17 08:06 Prontsevich

Actually, it would be useful if we want to add some custom text (computed programmatically) to the dateFormat.

pierfreeman avatar Dec 21 '17 11:12 pierfreeman

Hi. @Prontsevich I had that problem. I solve apply ngDoCheck and reassign the date.

public ngDoCheck(){ this.formatDate = "Here new format"; this.startDate = new Date(this.startDate); }

iariasfallas avatar May 31 '18 16:05 iariasfallas

The issue still persists in v.7 Tried both adding the format in locale and using dateformat property but the date displayed in the field doesn't update when locale/format changes. It only updates after selecting a new date.

vangras avatar Jan 21 '19 13:01 vangras

I am facing the same issue in the current version from npm ([email protected]).

It seems the issue could be resolved internally by changing [dateFormat] input to call this.updateInputfield whenever the input is set with a new format, in order to trigger the reformatting of the displayed value.

Maybe the maintainers @cagataycivici @yigitfindikli could confirm if this is ok?

From this (present version below): https://github.com/primefaces/primeng/blob/262a4181fb0882e108aa90c738c6abe9ceb08752/src/app/components/calendar/calendar.ts#L241

to that:

    _dateFormat: string = 'mm/dd/yy';

    @Input() get dateFormat(): string {
      return this._dateFormat;
    }
    
    set dateFormat(dateFormat: string) {
        this._dateFormat = dateFormat;
        this.updateInputfield();
    }

The same behaviour is already done for [showTime] input setter: (present version below) https://github.com/primefaces/primeng/blob/262a4181fb0882e108aa90c738c6abe9ceb08752/src/app/components/calendar/calendar.ts#L522-L533

Last, but not least, thank you a lot for a very good library :)

mariaro avatar Feb 19 '20 11:02 mariaro

This issue is still present in version 11.3.0 - are there plans to fix it? This behavior is not very nice in localised apps.

VILLAN3LL3 avatar Mar 18 '21 14:03 VILLAN3LL3

This issue is still present in version 11.3.0 - are there plans to fix it? This behavior is not very nice in localised apps.

I have the same issue. When switching language in our app all goes well (using the [locale]) but there is no normal way (either via the [locale] or [dateFormat] to enforce rerendering the selected date(time).

quartelh avatar Mar 22 '21 18:03 quartelh

I’m unable to replicate with the latest PrimeNG. If the issue still persists with the new version please create a new issue with our stackblitz template. https://stackblitz.com/github/primefaces/primeng-issue-template

yigitfindikli avatar Jan 27 '22 07:01 yigitfindikli

Same problem here with PrimeNG 9. If if has been solved, it would be great to port the solution to previous versions :-)

twopelu avatar Sep 19 '22 11:09 twopelu