fix(StatusInput): ensure validation is performed on initialization

Closes #326
This commit is contained in:
Pascal Precht 2021-08-16 14:17:55 +02:00 committed by Michał Cieślak
parent 01c5557621
commit 3c6147c69c
1 changed files with 21 additions and 18 deletions

View File

@ -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 {