aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/TextInput.kt
blob: 7b3510ac2d9e8ac66d705c6f58cfb7e3b057a06e (plain)
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
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, value: String? = null, classes: Set<String> = setOf()) :
        AbstractTextInput(value, 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")
    }

    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
    }
}