From d808d352709729c2058314f880323b5b87e098aa Mon Sep 17 00:00:00 2001 From: Edvin Syse Date: Wed, 26 Dec 2018 11:09:34 +0100 Subject: [PATCH] - Spinner.required() validator (https://github.com/edvin/tornadofx/issues/871) --- CHANGELOG.md | 1 + src/main/java/tornadofx/ViewModel.kt | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43777bf93..fdea240e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - The Workspace inside the `scope` of a UIComponents will assume the Workspace it is docked in (https://github.com/edvin/tornadofx/issues/806) - Kotlin 1.3.11 - bindSelected for ViewModel gets `out` modifier (https://github.com/edvin/tornadofx/issues/823) +- Spinner.required() validator (https://github.com/edvin/tornadofx/issues/871) ### Additions diff --git a/src/main/java/tornadofx/ViewModel.kt b/src/main/java/tornadofx/ViewModel.kt index 808af3d28..4cbcc1abc 100644 --- a/src/main/java/tornadofx/ViewModel.kt +++ b/src/main/java/tornadofx/ViewModel.kt @@ -467,6 +467,9 @@ inline fun ChoiceBox.validator(trigger: ValidationTrigger = Valid inline fun Spinner.validator(trigger: ValidationTrigger = ValidationTrigger.OnChange(), noinline validator: ValidationContext.(T?) -> ValidationMessage?) = validator(this, valueFactory.valueProperty(), trigger, validator) +inline fun Spinner.required(trigger: ValidationTrigger = tornadofx.ValidationTrigger.OnChange(), message: String? = tornadofx.viewModelBundle["required"]) + = validator(trigger) { if (it == null) error(message) else null } + /** * Add a validator to a TextInputControl that is already bound to a model property. */