aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/select
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-11-25 13:39:39 +0100
committerRobert Jaros <rjaros@finn.pl>2017-11-25 13:39:39 +0100
commit343390df5a0e01f45539939291c35d535a1b8af6 (patch)
treefcba5b87efa1b740bd5a011739af1e066cba28f0 /src/main/kotlin/pl/treksoft/kvision/form/select
parent4a31ea44d479358658a614ad56a5675436260813 (diff)
downloadkvision-343390df5a0e01f45539939291c35d535a1b8af6.tar.gz
kvision-343390df5a0e01f45539939291c35d535a1b8af6.tar.bz2
kvision-343390df5a0e01f45539939291c35d535a1b8af6.zip
Form validation
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/select')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt31
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt19
2 files changed, 30 insertions, 20 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt
index 4b991605..2d750683 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt
@@ -1,16 +1,19 @@
package pl.treksoft.kvision.form.select
+import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.form.FieldLabel
-import pl.treksoft.kvision.form.StringFormField
+import pl.treksoft.kvision.form.HelpBlock
+import pl.treksoft.kvision.form.StringFormControl
import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.snabbdom.SnOn
+import pl.treksoft.kvision.snabbdom.StringBoolPair
import pl.treksoft.kvision.snabbdom.StringPair
@Suppress("TooManyFunctions")
open class Select(options: List<StringPair>? = null, value: String? = null,
multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null,
- rich: Boolean = false) : SimplePanel(setOf("form-group")), StringFormField {
+ rich: Boolean = false) : SimplePanel(setOf("form-group")), StringFormControl {
var options
get() = input.options
@@ -99,15 +102,17 @@ open class Select(options: List<StringPair>? = null, value: String? = null,
}
private val idc = "kv_form_select_" + counter
- val input: SelectInput = SelectInput(options, value, multiple, ajaxOptions,
+ final override val input: SelectInput = SelectInput(options, value, multiple, ajaxOptions,
setOf("form-control")).apply { id = idc }
- val flabel: FieldLabel = FieldLabel(idc, label, rich)
+ final override val flabel: FieldLabel = FieldLabel(idc, label, rich)
+ final override val validationInfo: HelpBlock = HelpBlock().apply { visible = false }
init {
- this.addInternal(flabel)
@Suppress("LeakingThis")
input.eventTarget = this
+ this.addInternal(flabel)
this.addInternal(input)
+ this.addInternal(validationInfo)
counter++
}
@@ -115,6 +120,14 @@ open class Select(options: List<StringPair>? = null, value: String? = null,
var counter = 0
}
+ override fun getSnClass(): List<StringBoolPair> {
+ val cl = super.getSnClass().toMutableList()
+ if (validatorError != null) {
+ cl.add("has-error" to true)
+ }
+ return cl
+ }
+
@Suppress("UNCHECKED_CAST")
override fun <T : Widget> setEventListener(block: SnOn<T>.() -> Unit): Widget {
input.setEventListener(block)
@@ -131,17 +144,17 @@ open class Select(options: List<StringPair>? = null, value: String? = null,
return this
}
- override fun add(child: Widget): SimplePanel {
+ override fun add(child: Component): SimplePanel {
input.add(child)
return this
}
- override fun addAll(children: List<Widget>): SimplePanel {
+ override fun addAll(children: List<Component>): SimplePanel {
input.addAll(children)
return this
}
- override fun remove(child: Widget): SimplePanel {
+ override fun remove(child: Component): SimplePanel {
input.remove(child)
return this
}
@@ -151,7 +164,7 @@ open class Select(options: List<StringPair>? = null, value: String? = null,
return this
}
- override fun getChildren(): List<Widget> {
+ override fun getChildren(): List<Component> {
return input.getChildren()
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt
index c95cf434..2dcbe99b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt
@@ -3,9 +3,8 @@ package pl.treksoft.kvision.form.select
import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.CssSize
import pl.treksoft.kvision.core.KVManager.KVNULL
-import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.form.INPUTSIZE
-import pl.treksoft.kvision.form.StringFormField
import pl.treksoft.kvision.html.BUTTONSTYLE
import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.snabbdom.StringBoolPair
@@ -20,7 +19,7 @@ enum class SELECTWIDTHTYPE(val value: String) {
@Suppress("TooManyFunctions")
open class SelectInput(options: List<StringPair>? = null, value: String? = null,
multiple: Boolean = false, ajaxOptions: AjaxOptions? = null,
- classes: Set<String> = setOf()) : SimplePanel(classes), StringFormField {
+ classes: Set<String> = setOf()) : SimplePanel(classes) {
internal var options = options
set(value) {
@@ -28,14 +27,12 @@ open class SelectInput(options: List<StringPair>? = null, value: String? = null,
setChildrenFromOptions()
}
- @Suppress("LeakingThis")
- override var value: String? = value
+ var value: String? = value
set(value) {
field = value
refreshState()
}
- @Suppress("LeakingThis")
var startValue: String? = value
set(value) {
field = value
@@ -93,7 +90,7 @@ open class SelectInput(options: List<StringPair>? = null, value: String? = null,
field = value
setChildrenFromOptions()
}
- override var disabled: Boolean = false
+ var disabled: Boolean = false
set(value) {
field = value
refresh()
@@ -103,7 +100,7 @@ open class SelectInput(options: List<StringPair>? = null, value: String? = null,
field = value
refresh()
}
- override var size: INPUTSIZE? = null
+ var size: INPUTSIZE? = null
set(value) {
field = value
refresh()
@@ -140,19 +137,19 @@ open class SelectInput(options: List<StringPair>? = null, value: String? = null,
return kvh("select", childrenVNodes())
}
- override fun add(child: Widget): SimplePanel {
+ override fun add(child: Component): SimplePanel {
super.add(child)
refreshSelectInput()
return this
}
- override fun addAll(children: List<Widget>): SimplePanel {
+ override fun addAll(children: List<Component>): SimplePanel {
super.addAll(children)
refreshSelectInput()
return this
}
- override fun remove(child: Widget): SimplePanel {
+ override fun remove(child: Component): SimplePanel {
super.remove(child)
refreshSelectInput()
return this