aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/form
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-10-08 21:56:05 +0200
committerRobert Jaros <rjaros@finn.pl>2018-10-08 21:56:05 +0200
commiteddd58f3f31954809645bdf2222833424c3f9a73 (patch)
tree7fa78211eda8ce93b51738ba2c0774b7f05ca4c9 /src/main/kotlin/pl/treksoft/kvision/form
parent0d3e7c87bf74948f83ce006a1d340b0f3f5e68b0 (diff)
downloadkvision-eddd58f3f31954809645bdf2222833424c3f9a73.tar.gz
kvision-eddd58f3f31954809645bdf2222833424c3f9a73.tar.bz2
kvision-eddd58f3f31954809645bdf2222833424c3f9a73.zip
Testing modules.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/Form.kt23
1 files changed, 22 insertions, 1 deletions
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)
}
}