From 3c6147c69c845b49e061cc9c6140fd06360b4004 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Mon, 16 Aug 2021 14:17:55 +0200 Subject: [PATCH] fix(StatusInput): ensure validation is performed on initialization Closes #326 --- .../src/StatusQ/Controls/StatusInput.qml | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/ui/StatusQ/src/StatusQ/Controls/StatusInput.qml b/ui/StatusQ/src/StatusQ/Controls/StatusInput.qml index 04d6f3cfe4..0613b3ad58 100644 --- a/ui/StatusQ/src/StatusQ/Controls/StatusInput.qml +++ b/ui/StatusQ/src/StatusQ/Controls/StatusInput.qml @@ -32,6 +32,26 @@ Item { property var errors: ({}) + function validate() { + if (validators.length) { + for (let idx in validators) { + let result = validators[idx].validate(statusBaseInput.text) + + if (typeof result === "boolean" && result) { + statusBaseInput.valid = true + } else { + if (!errors) { + errors = {} + } + errors[validators[idx].name] = result + statusBaseInput.valid = false + } + } + } + } + + Component.onCompleted: validate() + StatusBaseText { id: label height: visible ? 17 : 0 @@ -74,24 +94,7 @@ Item { anchors.rightMargin: 16 maximumLength: root.charLimit - - onTextChanged: { - if (root.validators.length) { - for (let idx in root.validators) { - let result = root.validators[idx].validate(statusBaseInput.text) - - if (typeof result === "boolean" && result) { - statusBaseInput.valid = true - } else { - if (!root.errors) { - root.errors = {} - } - root.errors[root.validators[idx].name] = result - statusBaseInput.valid = false - } - } - } - } + onTextChanged: root.validate() } StatusBaseText {