fix display_format="hⓂ️s" for r/o only gave one best matching unit (eg. 5m) not all units (eg. 0:05:30)

This commit is contained in:
ralf 2022-02-25 10:16:28 +02:00
parent 83cfb34c3c
commit 832725ce52
3 changed files with 20 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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"]);