kvision / pl.treksoft.kvision.form / Form

Form

class Form<K>

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

Constructors

<init>

Form(panel: FormPanel<K>? = null, modelFactory: (Map<String, Any?>) -> K)

Creates a form with a given modelFactory function

Functions

add

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

Adds a control to the form.

clearData

fun clearData(): Unit

Sets the values of all controls to null.

get

operator fun get(key: String): Any?

Returns a value of the control of given key.

getControl

fun getControl(key: String): 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: String): 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.