kvision / pl.treksoft.kvision.form / FormPanel

FormPanel

open class FormPanel<K : Any> : SimplePanel

Bootstrap form component.

Constructors

<init>

FormPanel(method: FormMethod? = null, action: String? = null, enctype: FormEnctype? = null, type: FormType? = null, classes: Set<String> = setOf(), serializer: KSerializer<K>)

Properties

action

var action: String?

The URL address to send data.

autocomplete

var autocomplete: Boolean?

Determines if the form should have autocomplete.

enctype

var enctype: FormEnctype?

The form encoding type.

method

var method: FormMethod?

HTTP method.

name

var name: String?

The form name.

novalidate

var novalidate: Boolean?

Determines if the form is not validated.

target

var target: FormTarget?

The form target.

validator

var validator: ((Form<K>) -> Boolean?)?

Validation function.

validatorMessage

var validatorMessage: ((Form<K>) -> String?)?

Function returning validation message.

Functions

add

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

Adds a string control to the form panel.

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

Adds a boolean control to the form panel.

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

Adds a number control to the form panel.

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

Adds a date control to the form panel.

open 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): FormPanel<K>

Adds a files control to the form panel.

addInternal

fun <C : FormControl> addInternal(key: KProperty1<K, *>, control: C, required: Boolean = false, requiredMessage: String? = null, validatorMessage: ((C) -> String?)? = null, validator: ((C) -> Boolean?)? = null): FormPanel<K>

clearData

open 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

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

Returns a control of given key.

getData

open fun getData(): K

Returns current data model.

getDataJson

open fun getDataJson(): Json

Returns current data model as JSON.

getSnAttrs

open fun getSnAttrs(): List<StringPair>

Returns list of element attributes in the form of a List.

getSnClass

open fun getSnClass(): List<StringBoolPair>

Returns list of CSS class names for current widget in the form of a List.

remove

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

Removes a control from the form panel.

removeAll

open fun removeAll(): FormPanel<K>

Removes all children from the current container.

render

open fun render(): VNode

Renders current component as a Snabbdom vnode.

setData

open fun setData(model: K): Unit

Sets the values of all the controls from the model.

validate

open fun validate(): Boolean

Invokes validator function and validates the form.

Inherited Functions

add

open fun add(child: Component): SimplePanel

Adds given component to the current container.

addAll

open fun addAll(children: List<Component>): SimplePanel

Adds a list of components to the current container.

addInternal

fun addInternal(child: Component): SimplePanel

Protected and final method to add given component to the current container.

childrenVNodes

open fun childrenVNodes(): Array<VNode>

Returns the array of the children Snabbdom vnodes.

getChildren

open fun getChildren(): List<Component>

Returns a list of children of the current container.

remove

open fun remove(child: Component): SimplePanel

Removes given component from the current container.

Companion Object Functions

create

fun <K : Any> create(method: FormMethod? = null, action: String? = null, enctype: FormEnctype? = null, type: FormType? = null, classes: Set<String> = setOf(), init: (FormPanel<K>.() -> Unit)? = null): FormPanel<K>

formPanel

fun <K : Any> Container.formPanel(method: FormMethod? = null, action: String? = null, enctype: FormEnctype? = null, type: FormType? = null, classes: Set<String> = setOf(), init: (FormPanel<K>.() -> Unit)? = null): FormPanel<K>

DSL builder extension function.

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> FormPanel<K>.getDataWithFileContent(): K

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