From 0ecae6728903740c4407fd4bb9ebab806c631f2f Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Tue, 16 Jan 2018 15:53:33 +0100 Subject: Radio button group form control --- src/main/kotlin/pl/treksoft/kvision/Showcase.kt | 8 +++++++- src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt | 2 +- src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt index dfdc5b6b..d7b76862 100644 --- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt +++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt @@ -462,7 +462,13 @@ class Showcase : ApplicationBase() { }, required = true) add("spinner", Spinner(label = "Spinner"), required = true) add("radiogroup", RadioGroup(listOf("o1" to "Pierwsza opcja", "o2" to "Druga opcja"), - inline = true, label = "Radio group"), required = true) + inline = true, label = "Radio group").apply { + setEventListener { + change = { e -> + println(self.value) + } + } + }, required = true) validator = { val result = it["text"] == it["textarea"] diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt index 1a28870a..696e2264 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt @@ -86,7 +86,7 @@ open class Radio(value: Boolean = false, extraValue: String? = null, label: Stri init { @Suppress("LeakingThis") - input.eventTarget = this + input.eventTarget = this.eventTarget ?: this this.addInternal(input) this.addInternal(flabel) this.addInternal(validationInfo) diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt index 43a0d4e4..50bd49fc 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/RadioGroup.kt @@ -55,7 +55,6 @@ open class RadioGroup(options: List? = null, value: String? = null, final override val validationInfo: HelpBlock = HelpBlock().apply { visible = false } init { - @Suppress("LeakingThis") setChildrenFromOptions() counter++ } @@ -103,8 +102,9 @@ open class RadioGroup(options: List? = null, value: String? = null, Radio(false, extraValue = it.first, label = it.second).apply { inline = tinline name = tidc + eventTarget = this@RadioGroup setEventListener { - change = { + change = { e -> this@RadioGroup.value = self.extraValue } } -- cgit