aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-10-28 23:45:26 +0200
committerRobert Jaros <rjaros@finn.pl>2017-10-28 23:45:26 +0200
commit06f297d68887c7934e66d2c757abc8bf619df66a (patch)
treea828eec09f0bdc99b0f3fd45972b8cead37fbdec /src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt
parent6b13b8909a302b0f0f2155b81b83cd5ab4d7a046 (diff)
downloadkvision-06f297d68887c7934e66d2c757abc8bf619df66a.tar.gz
kvision-06f297d68887c7934e66d2c757abc8bf619df66a.tar.bz2
kvision-06f297d68887c7934e66d2c757abc8bf619df66a.zip
Databinding components
Event handlers refactoring
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt
index 131793b8..07008ddd 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/CheckInput.kt
@@ -17,6 +17,16 @@ open class CheckInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, override v
init {
this.id = id
+ this.setInternalEventListener {
+ click = {
+ val v = getElementJQuery()?.prop("checked") as Boolean?
+ value = (v == true)
+ }
+ change = {
+ val v = getElementJQuery()?.prop("checked") as Boolean?
+ value = (v == true)
+ }
+ }
}
@Suppress("LeakingThis")
@@ -83,15 +93,17 @@ open class CheckInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, override v
}
override fun afterInsert(node: VNode) {
- this.getElementJQuery()?.on("change", { _, _ ->
- val v = getElementJQuery()?.prop("checked") as Boolean?
- value = (v == true)
- true
- })
- this.getElementJQuery()?.on("click", { _, _ ->
- val v = getElementJQuery()?.prop("checked") as Boolean?
- value = (v == true)
- true
- })
+ refreshCheckedState()
+ }
+
+ override fun afterPostpatch(node: VNode) {
+ refreshCheckedState()
+ }
+
+ private fun refreshCheckedState() {
+ val v = getElementJQuery()?.prop("checked") as Boolean?
+ if (this.value != v) {
+ getElementJQuery()?.prop("checked", this.value)
+ }
}
}