aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt
index 84ad5661..8f0a09e0 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/AbstractTextInput.kt
@@ -4,21 +4,27 @@ import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.snabbdom.StringBoolPair
import pl.treksoft.kvision.snabbdom.StringPair
-abstract class AbstractTextInput(override var value: String? = null,
+abstract class AbstractTextInput(value: String? = null,
classes: Set<String> = setOf()) : Widget(classes + "form-control"), StringFormField {
+
init {
- this.setInternalEventListener {
+ this.setInternalEventListener<AbstractTextInput> {
input = {
val v = getElementJQuery()?.`val`() as String?
if (v != null && v.isNotEmpty()) {
- value = v
+ self.value = v
} else {
- value = null
+ self.value = null
}
}
}
}
+ override var value: String? = value
+ set(value) {
+ field = value
+ refreshState()
+ }
@Suppress("LeakingThis")
var startValue: String? = value
set(value) {
@@ -96,4 +102,10 @@ abstract class AbstractTextInput(override var value: String? = null,
}
return sn
}
+
+ private fun refreshState() {
+ value?.let {
+ getElementJQuery()?.`val`(it)
+ } ?: getElementJQueryD()?.`val`(null)
+ }
}