kvision / pl.treksoft.kvision.form / Form

Form

(js) class Form<K : Any>

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

Constructors

(js)

<init>

Creates a form with a given modelFactory function

Form(panel: FormPanel<K>? = null, serializer: KSerializer<K>, customSerializers: Map<KClass<*>, KSerializer<*>>? = null)

Properties

(js)

fields

val fields: MutableMap<String, FormControl>
(js)

modelFactory

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

Functions

(js)

add

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

Adds a boolean 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 number 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 date 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 files 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>
(js)

addCustom

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

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

clearData

Sets the values of all controls to null.

fun clearData(): Unit
(js)

get

Returns a value of the control of given key.

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

getControl

Returns a control of given key.

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

getData

Returns current data model.

fun getData(): K
(js)

getDataJson

Returns current data model as JSON.

fun getDataJson(): Json
(js)

remove

Removes a control from the form.

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

removeAll

Removes all controls from the form.

fun removeAll(): Form<K>
(js)

setData

Sets the values of all the controls from the model.

fun setData(model: K): Unit
(js)

validate

Invokes validator function and validates the form.

fun validate(markFields: Boolean = true): Boolean

Companion Object Functions

(js)

create

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

Extension Functions

(js)

getContent

Returns file with the content read.

suspend fun <K : Any> Form<K>.getContent(key: KProperty1<K, List<KFile>?>, kFile: KFile): KFile
(js)

getDataWithFileContent

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

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