aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-10-19 15:22:42 +0200
committerRobert Jaros <rjaros@finn.pl>2017-10-19 15:22:42 +0200
commitd591af011d040d8ce2684f044b594d28ab358ef9 (patch)
tree89ec92f3d72d535dc6507b68b70ae326797b28eb /src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
parent6caae545b7961f9ba5f136d38730ecf026ab7fbb (diff)
downloadkvision-d591af011d040d8ce2684f044b594d28ab358ef9.tar.gz
kvision-d591af011d040d8ce2684f044b594d28ab358ef9.tar.bz2
kvision-d591af011d040d8ce2684f044b594d28ab358ef9.zip
Form controls: TextArea
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt95
1 files changed, 3 insertions, 92 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
index 08a39e87..6cf0f239 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
@@ -1,8 +1,6 @@
package pl.treksoft.kvision.form
import com.github.snabbdom.VNode
-import pl.treksoft.kvision.core.Widget
-import pl.treksoft.kvision.snabbdom.StringBoolPair
import pl.treksoft.kvision.snabbdom.StringPair
enum class TEXTINPUTTYPE(val type: String) {
@@ -11,92 +9,32 @@ enum class TEXTINPUTTYPE(val type: String) {
}
class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, placeholder: String? = null,
- override var value: String? = null, name: String? = null, maxlength: Int? = null,
- disabled: Boolean = false, id: String? = null,
- classes: Set<String> = setOf()) : Widget(classes + "form-control"), StringFormField {
- init {
- this.id = id
- }
+ value: String? = null, name: String? = null, maxlength: Int? = null,
+ disabled: Boolean = false, id: String? = null, classes: Set<String> = setOf()) :
+ AbstractTextInput(placeholder, value, name, maxlength, disabled, id, classes) {
- @Suppress("LeakingThis")
- var startValue: String? = value
- set(value) {
- field = value
- this.value = value
- refresh()
- }
var type: TEXTINPUTTYPE = type
set(value) {
field = value
refresh()
}
- var placeholder: String? = placeholder
- set(value) {
- field = value
- refresh()
- }
- var name: String? = name
- set(value) {
- field = value
- refresh()
- }
- var maxlength: Int? = maxlength
- set(value) {
- field = value
- refresh()
- }
- override var disabled: Boolean = disabled
- set(value) {
- field = value
- refresh()
- }
-
var autocomplete: Boolean? = null
set(value) {
field = value
refresh()
}
- var autofocus: Boolean? = null
- set(value) {
- field = value
- refresh()
- }
- var readonly: Boolean? = null
- set(value) {
- field = value
- refresh()
- }
- override var size: INPUTSIZE? = null
- set(value) {
- field = value
- refresh()
- }
override fun render(): VNode {
return kvh("input")
}
- override fun getSnClass(): List<StringBoolPair> {
- val cl = super.getSnClass().toMutableList()
- size?.let {
- cl.add(it.className to true)
- }
- return cl
- }
-
@Suppress("ComplexMethod")
override fun getSnAttrs(): List<StringPair> {
val sn = super.getSnAttrs().toMutableList()
sn.add("type" to type.type)
- placeholder?.let {
- sn.add("placeholder" to it)
- }
startValue?.let {
sn.add("value" to it)
}
- name?.let {
- sn.add("name" to it)
- }
autocomplete?.let {
if (it) {
sn.add("autocomplete" to "on")
@@ -104,33 +42,6 @@ class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, placeholder: String? =
sn.add("autocomplete" to "off")
}
}
- autofocus?.let {
- if (it) {
- sn.add("autofocus" to "autofocus")
- }
- }
- maxlength?.let {
- sn.add("maxlength" to ("" + it))
- }
- readonly?.let {
- if (it) {
- sn.add("readonly" to "readonly")
- }
- }
- if (disabled) {
- sn.add("disabled" to "true")
- }
return sn
}
-
- override fun afterInsert(node: VNode) {
- this.getElementJQuery()?.on("input", { _, _ ->
- val v = getElementJQuery()?.`val`() as String?
- if (v != null && v.isNotEmpty()) {
- value = v
- } else {
- value = null
- }
- })
- }
}