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
This commit is contained in:
parent
3c6147c69c
commit
4fe2d82208
|
@ -43,6 +43,8 @@ Item {
|
||||||
property int maximumLength: 0
|
property int maximumLength: 0
|
||||||
|
|
||||||
property bool valid: true
|
property bool valid: true
|
||||||
|
property bool pristine: true
|
||||||
|
property bool dirty: false
|
||||||
|
|
||||||
property StatusIconSettings icon: StatusIconSettings {
|
property StatusIconSettings icon: StatusIconSettings {
|
||||||
width: 24
|
width: 24
|
||||||
|
@ -67,7 +69,7 @@ Item {
|
||||||
|
|
||||||
border.width: 1
|
border.width: 1
|
||||||
border.color: {
|
border.color: {
|
||||||
if (!statusBaseInput.valid) {
|
if (!statusBaseInput.valid && statusBaseInput.dirty) {
|
||||||
return Theme.palette.dangerColor1;
|
return Theme.palette.dangerColor1;
|
||||||
}
|
}
|
||||||
if (edit.activeFocus) {
|
if (edit.activeFocus) {
|
||||||
|
@ -144,6 +146,12 @@ Item {
|
||||||
onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
|
onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
|
||||||
wrapMode: statusBaseInput.multiline ? Text.WrapAtWordBoundaryOrAnywhere : TextEdit.NoWrap
|
wrapMode: statusBaseInput.multiline ? Text.WrapAtWordBoundaryOrAnywhere : TextEdit.NoWrap
|
||||||
|
|
||||||
|
onActiveFocusChanged: {
|
||||||
|
if (statusBaseInput.pristine) {
|
||||||
|
statusBaseInput.pristine = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Keys.onReturnPressed: {
|
Keys.onReturnPressed: {
|
||||||
if (multiline) {
|
if (multiline) {
|
||||||
event.accepted = false
|
event.accepted = false
|
||||||
|
@ -161,6 +169,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
|
statusBaseInput.dirty = true
|
||||||
if (statusBaseInput.maximumLength > 0) {
|
if (statusBaseInput.maximumLength > 0) {
|
||||||
if (text.length > statusBaseInput.maximumLength) {
|
if (text.length > statusBaseInput.maximumLength) {
|
||||||
var cursor = cursorPosition;
|
var cursor = cursorPosition;
|
||||||
|
|
Loading…
Reference in New Issue