kvision / pl.treksoft.kvision.form / Form

Form

class Form<K : Any>

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

Constructors

<init>

Form(panel: FormPanel<K>? = null, serializer: KSerializer<K>)

Creates a form with a given modelFactory function

Properties

fields

val fields: MutableMap<String, FormControl>

modelFactory

val modelFactory: (Map<String, Any?>) -> K

Functions

add

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

Adds a string 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): Form<K>

Adds a 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): Form<K>

Adds a number control to the form.

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

Adds a date control to the form.

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

Adds a files control to the form.

clearData

fun clearData(): Unit

Sets the values of all controls to null.

get

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

Returns a value of the control of given key.

getControl

fun getControl(key: KProperty1<K, *>): FormControl?

Returns a control of given key.

getData

fun getData(): K

Returns current data model.

getDataJson

fun getDataJson(): Json

Returns current data model as JSON.

remove

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

Removes a control from the form.

removeAll

fun removeAll(): Form<K>

Removes all controls from the form.

setData

fun setData(model: K): Unit

Sets the values of all the controls from the model.

validate

fun validate(): Boolean

Invokes validator function and validates the form.

Companion Object Functions

create

fun <K : Any> create(panel: FormPanel<K>? = null, init: (Form<K>.() -> Unit)? = null): Form<K>

Extension Functions

createInstance

fun <T> Any?.createInstance(vararg args: dynamic): T

Helper function for creating JavaScript objects from dynamic constructors.

getDataWithFileContent

suspend fun <K : Any> Form<K>.getDataWithFileContent(): K

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