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).
This commit is contained in:
parent
de776e4567
commit
af8d2036f3
|
@ -30,10 +30,18 @@ Item {
|
||||||
property int charLimit: 0
|
property int charLimit: 0
|
||||||
property string errorMessage: ""
|
property string errorMessage: ""
|
||||||
property list<StatusValidator> validators
|
property list<StatusValidator> 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: ({})
|
property var errors: ({})
|
||||||
|
|
||||||
function validate() {
|
function validate() {
|
||||||
|
if (!statusBaseInput.dirty && validationMode === StatusInput.ValidationMode.OnlyWhenDirty) {
|
||||||
|
return
|
||||||
|
}
|
||||||
statusBaseInput.valid = true
|
statusBaseInput.valid = true
|
||||||
if (validators.length) {
|
if (validators.length) {
|
||||||
for (let idx in validators) {
|
for (let idx in validators) {
|
||||||
|
|
Loading…
Reference in New Issue