fix(StatusInput): ensure validation is performed on initialization
Closes #326
This commit is contained in:
parent
01c5557621
commit
3c6147c69c
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue