diff options
| author | Robert Jaros <rjaros@finn.pl> | 2020-02-26 13:30:23 +0100 |
|---|---|---|
| committer | Robert Jaros <rjaros@finn.pl> | 2020-02-26 13:30:23 +0100 |
| commit | 99dcb8e434d7e0ccf5dada379c1b03e894e6aa82 (patch) | |
| tree | 25e6a9d47fdbddfc2af2d97eae35e1dba8d44490 /src/main/kotlin/pl/treksoft/kvision/form/check | |
| parent | 9a8525f2e5cb50071c076032fdcef5a48060108e (diff) | |
| download | kvision-99dcb8e434d7e0ccf5dada379c1b03e894e6aa82.tar.gz kvision-99dcb8e434d7e0ccf5dada379c1b03e894e6aa82.tar.bz2 kvision-99dcb8e434d7e0ccf5dada379c1b03e894e6aa82.zip | |
Major changes in the event handling architecture. Support for multiple event handlers.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/check')
3 files changed, 26 insertions, 13 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt index 8575b09e..7dae0f86 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt @@ -123,15 +123,21 @@ open class CheckBox( } @Suppress("UNCHECKED_CAST") - override fun <T : Widget> setEventListener(block: SnOn<T>.() -> Unit): Widget { - input.setEventListener(block) - return this + override fun <T : Widget> setEventListener(block: SnOn<T>.() -> Unit): Int { + return input.setEventListener(block) } - @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) - override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Deprecated( + "Use onEvent extension function instead.", + ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent") + ) + override fun setEventListener(block: SnOn<Widget>.() -> Unit): Int { @Suppress("DEPRECATION") - input.setEventListener(block) + return input.setEventListener(block) + } + + override fun removeEventListener(id: Int): Widget { + input.removeEventListener(id) return this } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt index f93fd436..b5c3ead0 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt @@ -26,6 +26,7 @@ import org.w3c.dom.events.MouseEvent import pl.treksoft.kvision.core.StringBoolPair import pl.treksoft.kvision.core.StringPair import pl.treksoft.kvision.core.Widget +import pl.treksoft.kvision.core.onEvent import pl.treksoft.kvision.form.FormInput import pl.treksoft.kvision.form.InputSize import pl.treksoft.kvision.form.ValidationStatus @@ -52,7 +53,7 @@ abstract class CheckInput( ) : Widget(classes), FormInput { init { - this.setInternalEventListener<CheckInput> { + this.onEvent { click = { val v = getElementJQuery()?.prop("checked") as Boolean? self.value = (v == true) 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 bef7f078..4d8a1607 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt @@ -133,15 +133,21 @@ open class Radio( } @Suppress("UNCHECKED_CAST") - override fun <T : Widget> setEventListener(block: SnOn<T>.() -> Unit): Widget { - input.setEventListener(block) - return this + override fun <T : Widget> setEventListener(block: SnOn<T>.() -> Unit): Int { + return input.setEventListener(block) } - @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) - override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Deprecated( + "Use onEvent extension function instead.", + ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent") + ) + override fun setEventListener(block: SnOn<Widget>.() -> Unit): Int { @Suppress("DEPRECATION") - input.setEventListener(block) + return input.setEventListener(block) + } + + override fun removeEventListener(id: Int): Widget { + input.removeEventListener(id) return this } |
