diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-10-08 21:56:05 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-10-08 21:56:05 +0200 |
commit | eddd58f3f31954809645bdf2222833424c3f9a73 (patch) | |
tree | 7fa78211eda8ce93b51738ba2c0774b7f05ca4c9 /src/main | |
parent | 0d3e7c87bf74948f83ce006a1d340b0f3f5e68b0 (diff) | |
download | kvision-eddd58f3f31954809645bdf2222833424c3f9a73.tar.gz kvision-eddd58f3f31954809645bdf2222833424c3f9a73.tar.bz2 kvision-eddd58f3f31954809645bdf2222833424c3f9a73.zip |
Testing modules.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt | 3 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/form/Form.kt | 23 |
2 files changed, 25 insertions, 1 deletions
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 @@ -43,6 +43,27 @@ internal data class FieldParams<in F : FormControl>( ) /** + * A wrapper for a Map with a custom containsKey method implementation. + * Used with kotlinx.serialization Mapper. + */ +private class FormMapWrapper<out V>(private val map: Map<String, V>) : Map<String, V> { + 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<String> get() = map.keys + override val values: Collection<V> get() = map.values + override val entries: Set<Map.Entry<String, V>> get() = map.entries +} + +/** * The form definition class. Can be used directly or indirectly inside a [FormPanel]. * * @constructor Creates a form with a given modelFactory function @@ -82,7 +103,7 @@ class Form<K : Any>(private val panel: FormPanel<K>? = 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) } } |