From 832725ce52bbe1618227d41123dab1715db25656 Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 25 Feb 2022 10:16:28 +0200 Subject: [PATCH] fix display_format="h:m:s" for r/o only gave one best matching unit (eg. 5m) not all units (eg. 0:05:30) --- api/js/etemplate/Et2Date/Et2DateDuration.ts | 10 ++++++++++ api/js/etemplate/Et2Date/Et2DateDurationReadonly.ts | 8 ++++++++ api/js/etemplate/et2_widget_date.ts | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/api/js/etemplate/Et2Date/Et2DateDuration.ts b/api/js/etemplate/Et2Date/Et2DateDuration.ts index 1f3b4495ae..3484378b1c 100644 --- a/api/js/etemplate/Et2Date/Et2DateDuration.ts +++ b/api/js/etemplate/Et2Date/Et2DateDuration.ts @@ -260,6 +260,16 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) this.formatter = formatDuration; } + transformAttributes(attrs) + { + // Clean formats + if (typeof attrs.display_format === 'string') + { + attrs.display_format = attrs.display_format.replace(/[^dhms]/g,''); + } + super.transformAttributes(attrs); + } + get value() : string { let value = 0; diff --git a/api/js/etemplate/Et2Date/Et2DateDurationReadonly.ts b/api/js/etemplate/Et2Date/Et2DateDurationReadonly.ts index 35b465cebd..f662a963d0 100644 --- a/api/js/etemplate/Et2Date/Et2DateDurationReadonly.ts +++ b/api/js/etemplate/Et2Date/Et2DateDurationReadonly.ts @@ -32,6 +32,14 @@ export class Et2DateDurationReadonly extends Et2DateDuration ]; } + constructor() + { + super(); + + // Property defaults + this.select_unit = false; // otherwise just best matching unit will be used for eg. display_format "h:m:s" + } + get value() { return this.__value; diff --git a/api/js/etemplate/et2_widget_date.ts b/api/js/etemplate/et2_widget_date.ts index d96c1510a9..39d668ac8e 100644 --- a/api/js/etemplate/et2_widget_date.ts +++ b/api/js/etemplate/et2_widget_date.ts @@ -767,7 +767,7 @@ export class et2_date_duration extends et2_date } // Clean formats - this.options.display_format = this.options.display_format.replace(/[^dhms]/,''); + this.options.display_format = this.options.display_format.replace(/[^dhms]/g,''); if(!this.options.display_format) { // @ts-ignore @@ -1813,4 +1813,4 @@ export class et2_date_range extends et2_inputWidget */ ]; } -et2_register_widget(et2_date_range, ["date-range"]); +et2_register_widget(et2_date_range, ["date-range"]); \ No newline at end of file