From ea3408012f9600097d5a3d5749f1bc43ac8f2b6f Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Mon, 16 Aug 2021 14:21:55 +0200 Subject: [PATCH] feat(StatusBaseInput): introduce `dirty` and `pristine` properties These properties can be used to determine whether a user has either interacted with the form control, or changed its value. It's also used in initial validation to ensure validation is done but visually, form controls stay untouched. Closes #327 --- src/StatusQ/Controls/StatusBaseInput.qml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/StatusQ/Controls/StatusBaseInput.qml b/src/StatusQ/Controls/StatusBaseInput.qml index 1c38b9d8..a4b8ade1 100644 --- a/src/StatusQ/Controls/StatusBaseInput.qml +++ b/src/StatusQ/Controls/StatusBaseInput.qml @@ -43,6 +43,8 @@ Item { property int maximumLength: 0 property bool valid: true + property bool pristine: true + property bool dirty: false property StatusIconSettings icon: StatusIconSettings { width: 24 @@ -67,7 +69,7 @@ Item { border.width: 1 border.color: { - if (!statusBaseInput.valid) { + if (!statusBaseInput.valid && statusBaseInput.dirty) { return Theme.palette.dangerColor1; } if (edit.activeFocus) { @@ -144,6 +146,12 @@ Item { onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) wrapMode: statusBaseInput.multiline ? Text.WrapAtWordBoundaryOrAnywhere : TextEdit.NoWrap + onActiveFocusChanged: { + if (statusBaseInput.pristine) { + statusBaseInput.pristine = false + } + } + Keys.onReturnPressed: { if (multiline) { event.accepted = false @@ -161,6 +169,7 @@ Item { } onTextChanged: { + statusBaseInput.dirty = true if (statusBaseInput.maximumLength > 0) { if (text.length > statusBaseInput.maximumLength) { var cursor = cursorPosition;