From 1a6110433d39e75316b155e4486b482da270e603 Mon Sep 17 00:00:00 2001 From: sara Date: Mon, 11 Sep 2023 15:49:07 +0200 Subject: [PATCH] fix(core/forms): prints date even when formcontrol changes --- .../core/forms/src/read-only-date-field.html | 8 ++++- .../core/forms/src/read-only-date-field.ts | 34 ++++++++++--------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/projects/core/forms/src/read-only-date-field.html b/projects/core/forms/src/read-only-date-field.html index cc89f7065..4dbf138bd 100644 --- a/projects/core/forms/src/read-only-date-field.html +++ b/projects/core/forms/src/read-only-date-field.html @@ -1 +1,7 @@ -{{dateVal}} + + + {{dateVal}} + + {{formatDateField(ctrl.value)}} + + \ No newline at end of file diff --git a/projects/core/forms/src/read-only-date-field.ts b/projects/core/forms/src/read-only-date-field.ts index 6b96cf0f2..f148b8c0a 100644 --- a/projects/core/forms/src/read-only-date-field.ts +++ b/projects/core/forms/src/read-only-date-field.ts @@ -65,28 +65,30 @@ export class AjfReadOnlyDateFieldComponent extends CoreComponent { filter(control => control != null), map(ctrl => { if (ctrl) { - const val = ctrl.value; - if (val == null) { - return ''; - } - - let dt = null; - if (typeof val === 'string') { - dt = parse(val, 'yyyy-MM-dd', new Date()); - } else { - dt = toDate(val); - } - if (!isNaN(dt.valueOf())) { - const datePipe = new DatePipe(this._getCurrentLocale()); - return datePipe.transform(dt, 'shortDate') as string; - } - return ''; + this.formatDateField(ctrl.value); } return ''; }), ); } + formatDateField(val: any): string { + if (val == null) { + return ''; + } + let dt = null; + if (typeof val === 'string') { + dt = parse(val, 'yyyy-MM-dd', new Date()); + } else { + dt = toDate(val); + } + if (!isNaN(dt.valueOf())) { + const datePipe = new DatePipe(this._getCurrentLocale()); + return datePipe.transform(dt, 'shortDate') as string; + } + return ''; + } + private _getCurrentLocale(): string { const lang = this._ts.getActiveLang(); switch (lang) {