From d73a15841801f9e155d6ad278bc236bab006afd5 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Fri, 10 Sep 2021 12:47:45 +0200 Subject: [PATCH] feat(StatusInput): introduce `ValidationMode` This allows users to configure how validation is run. There are two modes: 1. `ValidationMode.OnlyWhenDirty` 2. `ValidationMode.Always` By default, validation happens when the inputs value changes, or on initial `Component.onCompleted` event. The first mode allows for not performing validation when the input field is blank and validation. isn't necessary (yet). --- src/StatusQ/Controls/StatusInput.qml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/StatusQ/Controls/StatusInput.qml b/src/StatusQ/Controls/StatusInput.qml index 02fecc82..5ca3ff18 100644 --- a/src/StatusQ/Controls/StatusInput.qml +++ b/src/StatusQ/Controls/StatusInput.qml @@ -30,10 +30,18 @@ Item { property int charLimit: 0 property string errorMessage: "" property list validators + property int validationMode: StatusInput.ValidationMode.OnlyWhenDirty + enum ValidationMode { + OnlyWhenDirty, // validates input only after it has become dirty + Always // validates input even before it has become dirty + } property var errors: ({}) function validate() { + if (!statusBaseInput.dirty && validationMode === StatusInput.ValidationMode.OnlyWhenDirty) { + return + } statusBaseInput.valid = true if (validators.length) { for (let idx in validators) {