From eddd58f3f31954809645bdf2222833424c3f9a73 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Mon, 8 Oct 2018 21:56:05 +0200 Subject: Testing modules. --- .../pl/treksoft/kvision/dropdown/DropDown.kt | 3 +++ src/main/kotlin/pl/treksoft/kvision/form/Form.kt | 23 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src/main/kotlin/pl') diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt index 5f5f789c..4ae1e93b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -142,6 +142,9 @@ open class DropDown( idc, text, icon, style, disabled, forNavbar, withCaret, setOf("dropdown") ) + + fun buttonId() = button.id + internal val list: DropDownListTag = DropDownListTag(idc, setOf("dropdown-menu")) init { diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt index b45eed60..19f7e68a 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Form.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Form.kt @@ -42,6 +42,27 @@ internal data class FieldParams( val validator: ((F) -> Boolean?)? = null ) +/** + * A wrapper for a Map with a custom containsKey method implementation. + * Used with kotlinx.serialization Mapper. + */ +private class FormMapWrapper(private val map: Map) : Map { + override fun equals(other: Any?): Boolean = map == other + override fun hashCode(): Int = map.hashCode() + override fun toString(): String = map.toString() + override val size: Int get() = map.size + override fun isEmpty(): Boolean = map.isEmpty() + override fun containsKey(key: String): Boolean = + if (key.indexOf('.') != -1) map.containsKey(key) else + !(map.containsKey("$key.time") || map.containsKey("$key.size")) + + override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value) + override fun get(key: String): V? = map[key] + override val keys: Set get() = map.keys + override val values: Collection get() = map.values + override val entries: Set> get() = map.entries +} + /** * The form definition class. Can be used directly or indirectly inside a [FormPanel]. * @@ -82,7 +103,7 @@ class Form(private val panel: FormPanel? = null, private val seriali else -> listOf(entry.key to entry.value) } }.toMap() - val mapper = Mapper.InNullableMapper(map) + val mapper = Mapper.InNullableMapper(FormMapWrapper(map)) mapper.decode(serializer) } } -- cgit