tornadofx / tornadofx / ValidationContext

ValidationContext

class ValidationContext

Types

Validator inner class Validator<T>

Constructors

<init> ValidationContext()

Properties

decorationProvider var decorationProvider: (ValidationMessage) -> Decorator?

The decoration provider decides what kind of decoration should be applied to a control when validation fails. The default decorator will paint a small triangle in the top left corner and display a Tooltip with the error message.

isValid val isValid: Boolean
valid val valid: ReadOnlyBooleanProperty

A boolean indicating the current validation status.

validators val validators: ObservableList<Validator<*>>

Functions

addValidator fun <T> addValidator(node: Node, property: ObservableValue<T>, trigger: ValidationTrigger = ValidationTrigger.OnChange(), validator: ValidationContext.(T?) -> ValidationMessage?): Validator<T>

Add the given validator to the given property. The supplied node will be decorated by the current decorationProvider for this context if validation fails.

fun <T> addValidator(validator: Validator<T>, decorateErrors: Boolean = true): Validator<T>fun addValidator(node: TextInputControl, trigger: ValidationTrigger = ValidationTrigger.OnChange(), validator: ValidationContext.(String?) -> ValidationMessage?): Validator<String>

Add validator for a TextInputControl and validate the controls textProperty. Useful when you dont bind against a ViewModel or other backing property.

error fun error(message: String? = null): ValidationMessage
info fun info(message: String? = null): ValidationMessage
success fun success(message: String? = null): ValidationMessage
validate fun validate(vararg fields: ObservableValue<*>): Boolean

Rerun all validators (or just the ones passed in) and return a boolean indicating if validation passed.

fun validate(focusFirstError: Boolean = true, decorateErrors: Boolean = true, failFast: Boolean = false, vararg fields: ObservableValue<*>): Boolean

Rerun all validators (or just the ones passed in) and return a boolean indicating if validation passed. It is allowed to pass inn fields that has no corresponding validator. They will register as validated.

warning fun warning(message: String? = null): ValidationMessage

Extension Functions

getProperty fun <T> Any.getProperty(prop: KMutableProperty1<*, T>): ObjectProperty<T>
observable fun <T : Any> Any.observable(propName: String): ObjectProperty<T>