How can I see validation decorators immediately wh...
# tornadofx
k
How can I see validation decorators immediately when first opening a form? I can tell that validation is happening because I also have it bound to a button, but the decorators don’t activate until I type into the field
d
I'm pretty new and I'm sure this is not the best practice... but this worked for me to show errors immediately.
Copy code
class SampleForm : View("Sample") {

    private val model: SampleViewModel by inject()

    init {
        runLater {
            model.validationContext.validate(decorateErrors = true)
        }
    }
 
    override val root = form {
        fieldset {
            field("sample: ") {
                textfield(model.sampleField).validator {
                    this.success("Woop woop")
                }
            }
        }
        buttonbar {
            button("Save") {
                enableWhen(model.valid)
            }
        }
    }
}
k
Awesome, thank you! I was trying something similar, but didn’t wrap it in
runLater
d
Ya it doesn't seem to want to work in the init without it. I'm not sure why, maybe one of the more experienced people could shed some light on that 😛
g
you can accomplish the same thing inside of
onDock
without the
runLater
👍 1
d
Riiiiiight. I couldn't remember the name of the start up method. Thanks!