diff options
author | Robert Jaros <rjaros@finn.pl> | 2017-11-03 15:42:58 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2017-11-03 15:42:58 +0100 |
commit | 960a82bafa9e9b1a8e07b0eaa20d5eebb72aabc2 (patch) | |
tree | f84a99dd839a7f611c771e89b28747b7cec8d3d6 /src | |
parent | b9a849b4ebf397b04b4b3c405de325b740b958aa (diff) | |
download | kvision-960a82bafa9e9b1a8e07b0eaa20d5eebb72aabc2.tar.gz kvision-960a82bafa9e9b1a8e07b0eaa20d5eebb72aabc2.tar.bz2 kvision-960a82bafa9e9b1a8e07b0eaa20d5eebb72aabc2.zip |
Select input components
Diffstat (limited to 'src')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/Showcase.kt | 3 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/form/Select.kt | 122 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/form/SelectInput.kt | 2 |
3 files changed, 126 insertions, 1 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt index 8821e94b..b4abad0c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt +++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt @@ -107,6 +107,9 @@ class Showcase : ApplicationBase() { } root.add(mbuttons3) + val select5 = Select(listOf("a" to "Pierwsza", "b" to "Druga"), "a", label = "Lista wyboru") + root.add(select5) + val container = SimplePanel(setOf("abc", "def")) val h1 = Tag(H1, "To jest <i>test pisania</i> tekstu", false, null, classes = setOf("test", "test2")) container.add(h1) diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Select.kt b/src/main/kotlin/pl/treksoft/kvision/form/Select.kt new file mode 100644 index 00000000..413178d2 --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/form/Select.kt @@ -0,0 +1,122 @@ +package pl.treksoft.kvision.form + +import pl.treksoft.kvision.core.Widget +import pl.treksoft.kvision.panel.SimplePanel +import pl.treksoft.kvision.snabbdom.SnOn +import pl.treksoft.kvision.snabbdom.StringPair + +open class Select(options: List<StringPair>? = null, value: String? = null, + multiple: Boolean = false, label: String? = null, + rich: Boolean = false) : SimplePanel(setOf("form-group")), StringFormField { + + var options + get() = input.options + set(value) { + input.options = value + } + override var value + get() = input.value + set(value) { + input.value = value + } + var startValue + get() = input.startValue + set(value) { + input.startValue = value + } + var name + get() = input.name + set(value) { + input.name = value + } + var multiple + get() = input.multiple + set(value) { + input.multiple = value + } + var maxOptions + get() = input.maxOptions + set(value) { + input.maxOptions = value + } + var liveSearch + get() = input.liveSearch + set(value) { + input.liveSearch = value + } + var placeholder + get() = input.placeholder + set(value) { + input.placeholder = value + } + var style + get() = input.style + set(value) { + input.style = value + } + var selectWidth + get() = input.selectWidth + set(value) { + input.selectWidth = value + } + var selectWidthType + get() = input.selectWidthType + set(value) { + input.selectWidthType = value + } + var emptyOption + get() = input.emptyOption + set(value) { + input.emptyOption = value + } + override var disabled + get() = input.disabled + set(value) { + input.disabled = value + } + var label + get() = flabel.text + set(value) { + flabel.text = value + } + var rich + get() = flabel.rich + set(value) { + flabel.rich = value + } + override var size + get() = input.size + set(value) { + input.size = value + } + + private val idc = "kv_form_select_" + counter + val input: SelectInput = SelectInput(options, value, multiple, setOf("form-control")).apply { id = idc } + val flabel: FieldLabel = FieldLabel(idc, label, rich) + + init { + this.addInternal(flabel) + this.addInternal(input) + counter++ + } + + companion object { + var counter = 0 + } + + @Suppress("UNCHECKED_CAST") + override fun <T : Widget> setEventListener(block: SnOn<T>.() -> Unit): Widget { + input.setEventListener(block) + return this + } + + override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + input.setEventListener(block) + return this + } + + override fun removeEventListeners(): Widget { + input.removeEventListeners() + return this + } +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/SelectInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/SelectInput.kt index 61c0240c..7ef29754 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/SelectInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/SelectInput.kt @@ -17,7 +17,7 @@ enum class SELECTWIDTHTYPE(val value: String) { class SelectInput(options: List<StringPair>? = null, override var value: String? = null, multiple: Boolean = false, classes: Set<String> = setOf()) : SimplePanel(classes), StringFormField { - private var options = options + internal var options = options set(value) { field = value setChildrenFromOptions() |