1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package pl.treksoft.kvision.form
import com.github.snabbdom.VNode
import pl.treksoft.kvision.snabbdom.StringPair
enum class TEXTINPUTTYPE(val type: String) {
TEXT("text"),
PASSWORD("password")
}
class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, placeholder: String? = null,
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) {
var type: TEXTINPUTTYPE = type
set(value) {
field = value
refresh()
}
var autocomplete: Boolean? = null
set(value) {
field = value
refresh()
}
override fun render(): VNode {
return kvh("input")
}
@Suppress("ComplexMethod")
override fun getSnAttrs(): List<StringPair> {
val sn = super.getSnAttrs().toMutableList()
sn.add("type" to type.type)
startValue?.let {
sn.add("value" to it)
}
autocomplete?.let {
if (it) {
sn.add("autocomplete" to "on")
} else {
sn.add("autocomplete" to "off")
}
}
return sn
}
}
|