Form

class Form<K : Any>(panel: FormPanel<K>? = null, serializer: <Error class: unknown class><K>? = null, customSerializers: Map<KClass<*>, <Error class: unknown class><out <Error class: unknown class>>>? = null)

The form definition class. Can be used directly or indirectly inside a FormPanel.

Parameters

K

model class type

panel

optional instance of FormPanel

serializer

a serializer for model type

customSerializers

a map of custom serializers for model type

Constructors

Link copied to clipboard
constructor(panel: FormPanel<K>? = null, serializer: <Error class: unknown class><K>? = null, customSerializers: Map<KClass<*>, <Error class: unknown class><out <Error class: unknown class>>>? = null)

Creates a form with a given modelFactory function

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val fields: <Error class: unknown class><String, FormControl>
Link copied to clipboard
val modelFactory: (Map<String, Any?>) -> K?

Functions

Link copied to clipboard
fun <C : FormControl> add(key: String, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: (C) -> String?? = null, validator: (C) -> Boolean?? = null)

Adds a form control to the form with a dynamic keys.

fun <C : DateFormControl> add(key: KProperty1<K, <Error class: unknown class>?>, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: (C) -> String?? = null, validator: (C) -> Boolean?? = null)

Adds a date control to the form.

fun <C : BoolFormControl> add(key: KProperty1<K, Boolean?>, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: (C) -> String?? = null, validator: (C) -> Boolean?? = null)

Adds a boolean control to the form.

fun <C : TriStateFormControl> add(key: KProperty1<K, Boolean?>, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: (C) -> String?? = null, validator: (C) -> Boolean?? = null)

Adds a nullable boolean control to the form.

fun <C : NumberFormControl> add(key: KProperty1<K, Number?>, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: (C) -> String?? = null, validator: (C) -> Boolean?? = null)

Adds a number control to the form.

fun <C : StringFormControl> add(key: KProperty1<K, String?>, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: (C) -> String?? = null, validator: (C) -> Boolean?? = null)

Adds a string control to the form.

fun <C : KFilesFormControl> add(key: KProperty1<K, List<<Error class: unknown class>>?>, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: (C) -> String?? = null, validator: (C) -> Boolean?? = null)

Adds a files control to the form.

Link copied to clipboard
fun <C : StringFormControl> addCustom(key: KProperty1<K, Any?>, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: (C) -> String?? = null, validator: (C) -> Boolean?? = null)

Adds a string control to the form bound to custom field type.

Link copied to clipboard
fun clearData()

Sets the values of all controls to null.

Link copied to clipboard

Clear validation information from all fields.

Link copied to clipboard
operator fun get(key: String): Any?

Returns a value of the control with a given dynamic key.

operator fun get(key: KProperty1<K, *>): Any?

Returns a value of the control with a given key.

Link copied to clipboard

Returns a control with a given dynamic key.

Returns a control with a given key.

Link copied to clipboard
fun getData(): K

Returns current data model.

Link copied to clipboard
fun getDataJson(): <Error class: unknown class>

Returns current data model as JSON.

Link copied to clipboard
suspend fun <K : Any> Form<K>.getDataWithFileContent(): K

Returns current data model with file content read for all KFiles controls.

Link copied to clipboard

Returns the first control added to the form.

Link copied to clipboard
fun remove(key: String)

Removes a control from the form with a dynamic keys.

fun remove(key: KProperty1<K, *>)

Removes a control from the form.

Link copied to clipboard
fun removeAll()

Removes all controls from the form.

Link copied to clipboard
fun setData(model: K)

Sets the values of all the controls from the model.

Link copied to clipboard
fun validate(markFields: Boolean = true): Boolean

Invokes validator function and validates the form.

fun validate(key: String, markField: Boolean = true): Boolean
fun validate(key: KProperty1<K, *>, markField: Boolean = true): Boolean

Invokes validator for a single form field.