From 77e8cc62ffc22c9a242e0a05b3fe307bcae5e6df Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 25 Mar 2024 13:13:21 -0600 Subject: [PATCH] Et2DateDuration: Roll over values greater than max into the next unit, if possible --- api/js/etemplate/Et2Date/Et2DateDuration.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/api/js/etemplate/Et2Date/Et2DateDuration.ts b/api/js/etemplate/Et2Date/Et2DateDuration.ts index 0bdc822e39..36be1c2a69 100644 --- a/api/js/etemplate/Et2Date/Et2DateDuration.ts +++ b/api/js/etemplate/Et2Date/Et2DateDuration.ts @@ -539,6 +539,21 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) } } + handleInputChange(event) + { + // Rather than error, roll over when possible + const changed = event.target; + if(typeof changed.max == "number" && parseInt(changed.value) >= changed.max) + { + const next = changed.previousElementSibling; + if(next) + { + next.value = next.valueAsNumber + Math.floor(changed.valueAsNumber / changed.max); + changed.value = changed.valueAsNumber % changed.max; + } + } + } + /** * Render the needed number inputs according to selectUnit & displayFormat properties * @@ -593,7 +608,9 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) exportparts="scroll:scroll,scrollbutton:scrollbutton" name=${input.name} min=${input.min} max=${input.max} precision=${input.precision} title=${input.title} - value=${input.value}>` + value=${input.value} + @sl-change=${this.handleInputChange} + >` )} `; }