Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Commit

Permalink
- Spinner.required() validator (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvin Syse committed Dec 26, 2018
1 parent cff8075 commit d808d35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tornadofx/ViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ inline fun <reified T> ChoiceBox<T>.validator(trigger: ValidationTrigger = Valid
inline fun <reified T> Spinner<T>.validator(trigger: ValidationTrigger = ValidationTrigger.OnChange(), noinline validator: ValidationContext.(T?) -> ValidationMessage?)
= validator(this, valueFactory.valueProperty(), trigger, validator)

inline fun <reified T> Spinner<T>.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.
*/
Expand Down

0 comments on commit d808d35

Please sign in to comment.