From 0607bd7f58ba28eca70154d62074885b3aa9c130 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 29 Jun 2021 09:26:39 +0200 Subject: [PATCH] MOBILE-3320 database: Fix some fields not displayed --- src/addons/mod/data/fields/date/component/date.ts | 8 ++++---- src/core/services/utils/dom.ts | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/addons/mod/data/fields/date/component/date.ts b/src/addons/mod/data/fields/date/component/date.ts index 5639572e9..5fa517dd7 100644 --- a/src/addons/mod/data/fields/date/component/date.ts +++ b/src/addons/mod/data/fields/date/component/date.ts @@ -36,6 +36,10 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo */ protected init(): void { if (this.displayMode) { + this.displayDate = this.value?.content + ? parseInt(this.value.content, 10) * 1000 + : undefined; + return; } @@ -62,10 +66,6 @@ export class AddonModDataFieldDateComponent extends AddonModDataFieldPluginCompo ? new Date(parseInt(this.value.content, 10) * 1000) : new Date(); - this.displayDate = this.value?.content - ? parseInt(this.value.content, 10) * 1000 - : undefined; - } this.addControl('f_' + this.field.id, CoreTimeUtils.toDatetimeFormat(date.getTime())); diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 5895170ad..789922816 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -407,7 +407,11 @@ export class CoreDomUtilsProvider { return size; } - size = Number(size); + if (typeof size == 'string') { + // It's important to use parseInt instead of Number because Number('') is 0 instead of NaN. + size = parseInt(size, 10); + } + if (!isNaN(size)) { return size + 'px'; }