Views
1 week ago

tornadofx-guide

11. Editing Models and

11. Editing Models and Validation There are multiple severity levels representing successful input to easier provide the contextually correct feedback in most cases. For example, you might want to give an informational message for a field no matter the input value, or specifically mark fields with a green checkbox when they are entered. The only severity that will result in an invalid status is the Error level. ValidationTrigger By default validation will happen when the input value changes. The input value is always an ObservableValue , and the default trigger simply listens for changes. You can however choose to validate when the input field looses focus, or when a save button is clicked for instance. The following ValidationTriggers can be configured for each validator: OnChange - Validate when input value changes, optionally after a given delay in milliseconds OnBlur - Validate when the input field looses focus Never - Only validate when ValidationContext.validate() is called ValidationContext Normally you would validate user input from multiple controls or input fields at once. You can gather these validators in a ValidationContext so you can check if all validators are valid, or ask the validation context to perform validation for all fields at any given time. The context also controls what kind of decorator will be used to convey the validation message for each field. See the Ad Hoc validation example below. Decorator The decorationProvider of a ValidationContext is in charge of providing feedback when a ValidationMessage is associated with an input. By default this is an instance of SimpleMessageDecorator which will mark the input field with a colored triangle in the topper left corner and display a popup with the message while the input has focus. 168

11. Editing Models and Validation Figure 11.2 The default decorator showing a required field validation message If you don't like the default decorator look you can easily create your own by implementing the Decorator interface: interface Decorator { fun decorate(node: Node) fun undecorate(node: Node) } You can assign your decorator to a given ValidationContext like this: context.decorationProvider = MyDecorator() Tip: You can create a decorator that applies CSS style classes to your inputs instead of overlaying other nodes to provide feedback. Ad Hoc Validation 169

GUIDE
Guide
GUIDE
GUIDE
Guide
GUIDE
GUIDE
GUIDE
guide
GUIDE
Guide
Guide
Guide