From 66093ae038e9f2f596ae29f7ace8dbc0051a818b Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 11 Sep 2024 10:57:32 -0600 Subject: [PATCH] Fix setting Et2DateDuration.value programmatically did not update UI --- api/js/etemplate/Et2Date/Et2DateDuration.ts | 15 ++++++++++++++- api/js/etemplate/Et2Textbox/Et2Number.ts | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/api/js/etemplate/Et2Date/Et2DateDuration.ts b/api/js/etemplate/Et2Date/Et2DateDuration.ts index 5671a60210..73ee71f3bb 100644 --- a/api/js/etemplate/Et2Date/Et2DateDuration.ts +++ b/api/js/etemplate/Et2Date/Et2DateDuration.ts @@ -17,6 +17,7 @@ import {dateStyles} from "./DateStyles"; import shoelace from "../Styles/shoelace"; import {customElement} from "lit/decorators/custom-element.js"; import {property} from "lit/decorators/property.js"; +import {live} from "lit/directives/live.js"; export interface formatOptions { @@ -363,6 +364,18 @@ export class Et2DateDuration extends Et2InputWidget(LitElement) set value(_value) { this._display = this._convert_to_display(this.emptyNot0 && ""+_value === "" ? '' : parseFloat(_value)); + // Update values + (typeof this._display.value == "string" ? this._display.value.split(":") : [this._display.value]) + .forEach((v, index) => + { + if(!this._durationNode[index]) + { + return; + } + const old = this._durationNode[index]?.value; + this._durationNode[index].value = v; + this._durationNode[index].requestUpdate("value", old); + }); this.requestUpdate(); } @@ -578,7 +591,7 @@ export class Et2DateDuration extends Et2InputWidget(LitElement) step=${this.step} precision=${typeof input.precision === "number" ? input.precision : nothing} title=${input.title || nothing} - value=${input.value} + value=${live(input.value)} @sl-change=${this.handleInputChange} >` )} diff --git a/api/js/etemplate/Et2Textbox/Et2Number.ts b/api/js/etemplate/Et2Textbox/Et2Number.ts index 2313eff17c..90417bad6e 100644 --- a/api/js/etemplate/Et2Textbox/Et2Number.ts +++ b/api/js/etemplate/Et2Textbox/Et2Number.ts @@ -218,6 +218,7 @@ export class Et2Number extends Et2Textbox @property({type: String}) set value(val) { + const old = this.value; if("" + val !== "") { // Remove separator so parseFloat works @@ -238,6 +239,7 @@ export class Et2Number extends Et2Textbox if(isNaN(val)) { super.value = val; + this.requestUpdate("value", old); return; } if(this.max && val > this.max) @@ -249,6 +251,8 @@ export class Et2Number extends Et2Textbox val = this.min; } super.value = formatNumber(val, this.decimalSeparator, this.thousandsSeparator, this.precision); + + this.requestUpdate("value", old); } get value() : string @@ -337,7 +341,7 @@ export class Et2Number extends Et2Textbox // The initial options need to match an actual number radix: this.decimalSeparator, thousandsSeparator: this.thousandsSeparator, - mask: this.mask ?? Number, + // mask: this.mask ?? Number, lazy: false, padFractionalZeros: (typeof this.precision !== "undefined"), definitions: {