aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form/check
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/check
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/check')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt15
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt11
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt14
3 files changed, 26 insertions, 14 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt
index e4dd7fe9..62403f8a 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt
@@ -1,8 +1,9 @@
package pl.treksoft.kvision.form.check
import pl.treksoft.kvision.core.Widget
-import pl.treksoft.kvision.form.BoolFormField
+import pl.treksoft.kvision.form.BoolFormControl
import pl.treksoft.kvision.form.FieldLabel
+import pl.treksoft.kvision.form.HelpBlock
import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.snabbdom.SnOn
import pl.treksoft.kvision.snabbdom.StringBoolPair
@@ -17,7 +18,7 @@ enum class CHECKBOXSTYLE(val className: String) {
}
open class CheckBox(value: Boolean = false, label: String? = null,
- rich: Boolean = false) : SimplePanel(setOf("checkbox")), BoolFormField {
+ rich: Boolean = false) : SimplePanel(setOf("checkbox")), BoolFormControl {
override var value
get() = input.value
@@ -71,14 +72,17 @@ open class CheckBox(value: Boolean = false, label: String? = null,
}
private val idc = "kv_form_checkbox_" + counter
- val input: CheckInput = CheckInput(CHECKINPUTTYPE.CHECKBOX, value, setOf("styled")).apply { id = idc }
- val flabel: FieldLabel = FieldLabel(idc, label, rich)
+ final override val input: CheckInput = CheckInput(CHECKINPUTTYPE.CHECKBOX, value,
+ setOf("styled")).apply { id = idc }
+ final override val flabel: FieldLabel = FieldLabel(idc, label, rich, classes = setOf())
+ final override val validationInfo: HelpBlock = HelpBlock().apply { visible = false }
init {
@Suppress("LeakingThis")
input.eventTarget = this
this.addInternal(input)
this.addInternal(flabel)
+ this.addInternal(validationInfo)
counter++
}
@@ -113,6 +117,9 @@ open class CheckBox(value: Boolean = false, label: String? = null,
if (inline) {
cl.add("checkbox-inline" to true)
}
+ if (validatorError != null) {
+ cl.add("has-error" to true)
+ }
return cl
}
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt
index a4899f45..a2ebd06d 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt
@@ -2,7 +2,6 @@ package pl.treksoft.kvision.form.check
import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.Widget
-import pl.treksoft.kvision.form.BoolFormField
import pl.treksoft.kvision.form.INPUTSIZE
import pl.treksoft.kvision.snabbdom.StringBoolPair
import pl.treksoft.kvision.snabbdom.StringPair
@@ -13,7 +12,7 @@ enum class CHECKINPUTTYPE(val type: String) {
}
open class CheckInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, value: Boolean = false,
- classes: Set<String> = setOf()) : Widget(classes), BoolFormField {
+ classes: Set<String> = setOf()) : Widget(classes) {
init {
this.setInternalEventListener<CheckInput> {
@@ -27,12 +26,12 @@ open class CheckInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, value: Boo
}
}
}
- override var value: Boolean = value
+
+ var value: Boolean = value
set(value) {
field = value
refreshState()
}
- @Suppress("LeakingThis")
var startValue: Boolean = value
set(value) {
field = value
@@ -49,7 +48,7 @@ open class CheckInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, value: Boo
field = value
refresh()
}
- override var disabled: Boolean = false
+ var disabled: Boolean = false
set(value) {
field = value
refresh()
@@ -59,7 +58,7 @@ open class CheckInput(type: CHECKINPUTTYPE = CHECKINPUTTYPE.CHECKBOX, value: Boo
field = value
refresh()
}
- override var size: INPUTSIZE? = null
+ var size: INPUTSIZE? = null
set(value) {
field = value
refresh()
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt
index 284cf26c..1a28870a 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt
@@ -1,8 +1,9 @@
package pl.treksoft.kvision.form.check
import pl.treksoft.kvision.core.Widget
-import pl.treksoft.kvision.form.BoolFormField
+import pl.treksoft.kvision.form.BoolFormControl
import pl.treksoft.kvision.form.FieldLabel
+import pl.treksoft.kvision.form.HelpBlock
import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.snabbdom.SnOn
import pl.treksoft.kvision.snabbdom.StringBoolPair
@@ -17,7 +18,7 @@ enum class RADIOSTYLE(val className: String) {
}
open class Radio(value: Boolean = false, extraValue: String? = null, label: String? = null,
- rich: Boolean = false) : SimplePanel(), BoolFormField {
+ rich: Boolean = false) : SimplePanel(), BoolFormControl {
override var value
get() = input.value
@@ -76,17 +77,19 @@ open class Radio(value: Boolean = false, extraValue: String? = null, label: Stri
}
private val idc = "kv_form_radio_" + counter
- val input: CheckInput = CheckInput(CHECKINPUTTYPE.RADIO, value).apply {
+ final override val input: CheckInput = CheckInput(CHECKINPUTTYPE.RADIO, value).apply {
this.id = idc
this.extraValue = extraValue
}
- val flabel: FieldLabel = FieldLabel(idc, label, rich)
+ final override val flabel: FieldLabel = FieldLabel(idc, label, rich, classes = setOf())
+ final override val validationInfo: HelpBlock = HelpBlock().apply { visible = false }
init {
@Suppress("LeakingThis")
input.eventTarget = this
this.addInternal(input)
this.addInternal(flabel)
+ this.addInternal(validationInfo)
counter++
}
@@ -129,6 +132,9 @@ open class Radio(value: Boolean = false, extraValue: String? = null, label: Stri
cl.add("checkbox-inline" to true)
}
}
+ if (validatorError != null) {
+ cl.add("has-error" to true)
+ }
return cl
}
}