diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-01-29 20:55:50 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-01-29 20:55:50 +0100 |
commit | 6cf546ffb334155b41af49cc7e2b25873204627d (patch) | |
tree | df3c1324c836829be06b2e96612e56c442a6f837 /src/main | |
parent | 9a70dcb74707dac6d7e88d9b75ddf36b17fd5632 (diff) | |
download | kvision-6cf546ffb334155b41af49cc7e2b25873204627d.tar.gz kvision-6cf546ffb334155b41af49cc7e2b25873204627d.tar.bz2 kvision-6cf546ffb334155b41af49cc7e2b25873204627d.zip |
Dedicated onClick event handler on buttons
Diffstat (limited to 'src/main')
4 files changed, 39 insertions, 0 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 4faee7e7..6776b8eb 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt @@ -1,5 +1,6 @@ package pl.treksoft.kvision.form.check +import org.w3c.dom.events.MouseEvent import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.form.BoolFormControl import pl.treksoft.kvision.form.FieldLabel @@ -126,4 +127,13 @@ open class CheckBox( } return cl } + + open fun onClick(handler: CheckBox.(MouseEvent) -> Unit): CheckBox { + this.setEventListener<CheckBox> { + click = { e -> + self.handler(e) + } + } + 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 a3ccd126..7114b2c2 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt @@ -1,6 +1,7 @@ package pl.treksoft.kvision.form.check import com.github.snabbdom.VNode +import org.w3c.dom.events.MouseEvent import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.form.INPUTSIZE import pl.treksoft.kvision.snabbdom.StringBoolPair @@ -110,4 +111,13 @@ open class CheckInput( getElementJQuery()?.prop("checked", this.value) } } + + open fun onClick(handler: CheckInput.(MouseEvent) -> Unit): CheckInput { + this.setEventListener<CheckInput> { + click = { e -> + self.handler(e) + } + } + return this + } } 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 4dc0ac90..d7fa502f 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt @@ -1,5 +1,6 @@ package pl.treksoft.kvision.form.check +import org.w3c.dom.events.MouseEvent import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.form.BoolFormControl import pl.treksoft.kvision.form.FieldLabel @@ -141,4 +142,13 @@ open class Radio( } return cl } + + open fun onClick(handler: Radio.(MouseEvent) -> Unit): Radio { + this.setEventListener<Radio> { + click = { e -> + self.handler(e) + } + } + return this + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt index ec0fd881..4e8f7b3e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt @@ -1,6 +1,7 @@ package pl.treksoft.kvision.html import com.github.snabbdom.VNode +import org.w3c.dom.events.MouseEvent import pl.treksoft.kvision.core.ResString import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.snabbdom.StringBoolPair @@ -87,4 +88,12 @@ open class Button( return super.getSnAttrs() + ("type" to "button") } + open fun onClick(handler: Button.(MouseEvent) -> Unit): Button { + this.setEventListener<Button> { + click = { e -> + self.handler(e) + } + } + return this + } } |