I am playing around with validation. When setting ...
# kvision
j
I am playing around with validation. When setting the validationStatus to INVALID on a text, the enclosing div is updated with the css class "text-danger". When I reset the validation status to "VALID" the css class is not removed. Any idea what I might miss?
r
Works for me. Tested with:
Copy code
val text = text()
            button("invalid").onClick {
                text.validationStatus = ValidationStatus.INVALID
            }
            button("valid").onClick {
                text.validationStatus = ValidationStatus.VALID
            }
            button("normal").onClick {
                text.validationStatus = null
            }
But you are probably doing something else, because there is no 'text-danger' class with this.
This adds
text-danger
class but works for me as well:
Copy code
val text = text()
            button("error").onClick {
                text.validatorError = "error message"
            }
            button("normal").onClick {
                text.validatorError = null
            }
j
Only happens with a label and a validationError set
Copy code
val text = text().apply{
              label = "daLabel"
            }

            button("invalid").onClick {
              text.validationStatus = ValidationStatus.INVALID
              text.validatorError = "Not a number!"
            }
            button("valid").onClick {
              text.validationStatus = ValidationStatus.VALID
            }
            button("normal").onClick {
              text.validationStatus = null
            }
Resetting the validationError removes the class
Ok, the state "validationStatus = VALID" and "validationError != null" doesn't make too much sense. But maybe bind the danger-text to "validationStatus" instead of "validationError"?
This might be better in cases where no validation error is set
r
validationStatus
is a property of input controls (e.g.
TextInput
), which don't contain labels and error messages. It's marked with border color only.
validatorError
, on the other hand, is a property of form controls (e.g.
Text
) which have labels and error messages. So if you want to show error text for form control use
validatorError
(it sets
validationStatus
automatically on the inner input). If you just want colored border use
validationStatus
(it's available for both types of control).
👍 1