From 4261d6d2c73ac7786f0b107141d42a32ec9a1bf6 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 26 Nov 2017 23:14:22 +0100 Subject: Form validation --- src/main/kotlin/pl/treksoft/kvision/form/Form.kt | 2 +- src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/main/kotlin/pl') diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt index 66f6f450..337152e3 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt @@ -56,7 +56,7 @@ open class Form(private val panel: FormPanel? = null, private val modelFac open fun getData(): K { val map = fields.entries.associateBy({ it.key }, { it.value.getValue() }) - return modelFactory(map) + return modelFactory(map.withDefault { null }) } open fun validate(): Boolean { diff --git a/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt b/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt index e996cfae..65015f3f 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/FormPanel.kt @@ -92,6 +92,14 @@ open class FormPanel(private val type: FORMTYPE? = null, classes: Set return this } + open fun getControl(key: String): FormControl? { + return form.getControl(key) + } + + operator fun get(key: String): Any? { + return getControl(key)?.getValue() + } + open fun setData(data: K) { form.setData(data) } -- cgit