From cfbb74b83ed509a47219ebd7129500582e9ce509 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 13 Sep 2022 13:00:25 -0600 Subject: [PATCH] Fix some Et2DateDuration bugs - Duration did not validate correctly - Validation errors were not actually shown - Empty duration ('') did not work consistently --- api/js/etemplate/Et2Date/Et2DateDuration.ts | 4 ++-- api/js/etemplate/Et2InputWidget/Et2InputWidget.ts | 5 ++++- api/src/Etemplate/Widget/Date.php | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/api/js/etemplate/Et2Date/Et2DateDuration.ts b/api/js/etemplate/Et2Date/Et2DateDuration.ts index 2435e68b98..b9d322633e 100644 --- a/api/js/etemplate/Et2Date/Et2DateDuration.ts +++ b/api/js/etemplate/Et2Date/Et2DateDuration.ts @@ -290,7 +290,7 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) } let val = this._durationNode.length ? this._durationNode[0].value : ''; - if(val === '') + if(val === '' || isNaN(val)) { return this.emptyNot0 ? '' : "0"; } @@ -496,7 +496,7 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) let input = { name: "", title: "", - value: value, + value: typeof value == "number" ? value : ((this.selectUnit ? value.pop() : value[i]) || ""), min: undefined, max: undefined }; diff --git a/api/js/etemplate/Et2InputWidget/Et2InputWidget.ts b/api/js/etemplate/Et2InputWidget/Et2InputWidget.ts index a56b6ab696..9dce3eb2c4 100644 --- a/api/js/etemplate/Et2InputWidget/Et2InputWidget.ts +++ b/api/js/etemplate/Et2InputWidget/Et2InputWidget.ts @@ -71,6 +71,9 @@ const Et2InputWidgetMixin = >(superclass : T) .input-group__container > .input-group__input ::slotted(.form-control) { width: 100%; } + .form-field__feedback { + position: relative; + } ` ]; @@ -411,13 +414,13 @@ const Et2InputWidgetMixin = >(superclass : T) let feedback = document.createElement("lion-validation-feedback"); feedback.feedbackData = feedbackData; feedback.slot = "help-text"; + this.append(feedback); if(this.shadowRoot.querySelector("slot[name='feedback']")) { feedback.slot = "feedback"; } else { - this.append(feedback); // Not always visible? (this.shadowRoot.querySelector("#help-text")).style.display = "initial"; } diff --git a/api/src/Etemplate/Widget/Date.php b/api/src/Etemplate/Widget/Date.php index e4b2568cb5..2198719ddf 100644 --- a/api/src/Etemplate/Widget/Date.php +++ b/api/src/Etemplate/Widget/Date.php @@ -165,7 +165,7 @@ class Date extends Transformer $value = self::get_array($content, $form_name); $valid =& self::get_array($validated, $form_name, true); - if($value && $this->type !== 'date-duration') + if($value && !in_array($this->type, ['et2-date-duration', 'date-duration'])) { try { @@ -193,7 +193,7 @@ class Date extends Transformer { $valid = null; } - elseif($this->type == 'date-duration') + elseif(in_array($this->type, ['et2-date-duration', 'date-duration'])) { $valid = (string)$value === '' ? '' : (int)$value; } @@ -256,7 +256,7 @@ class Date extends Transformer $value = $max; } } - if($this->type == 'date-duration') + if(in_array($this->type, ['et2-date-duration', 'date-duration'])) { $valid = (string)$value === '' ? '' : (int)$value; }