Skip to content

Commit f4c4e05

Browse files
authored
fix(module:date-picker): update input value when nzFormat changed (#9129)
1 parent e53e54d commit f4c4e05

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

components/date-picker/date-picker.component.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,23 @@ describe('NzDatePickerComponent', () => {
374374
expect(input.value).toBe('24.02.2020');
375375
}));
376376

377+
it('should rerender input value when nzFormat changed', fakeAsync(() => {
378+
fixtureInstance.nzFormat = 'dd.MM.yyyy';
379+
fixtureInstance.nzValue = new Date('2025-05-23');
380+
fixture.detectChanges();
381+
flush();
382+
fixture.detectChanges();
383+
const input = getPickerInput(fixture.debugElement);
384+
expect(input.value).toBe('23.05.2025');
385+
const nzOnChange = spyOn(fixtureInstance, 'nzOnChange');
386+
fixtureInstance.nzFormat = 'dd/MM/yyyy';
387+
fixture.detectChanges();
388+
flush();
389+
fixture.detectChanges();
390+
expect(input.value).toBe('23/05/2025');
391+
expect(nzOnChange).not.toHaveBeenCalled();
392+
}));
393+
377394
it('should support nzDisabledDate', fakeAsync(() => {
378395
fixture.detectChanges();
379396
const compareDate = new Date('2018-11-15 00:00:00');

components/date-picker/date-picker.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, AfterViewInit,
745745

746746
if (nzFormat?.currentValue) {
747747
this.isCustomFormat = true;
748+
this.updateInputValue();
748749
}
749750

750751
if (nzLocale) {

0 commit comments

Comments
 (0)