selectField

fun <T> RenderContext.selectField(styling: BasicParams.() -> Unit = {}, items: List<T>, value: Store<T>? = null, baseClass: StyleClass = StyleClass.None, id: String? = value?.id, prefix: String = "selectField", build: SelectFieldComponent<T>.() -> Unit): Label

This function generates a selectField element. So this supports the use case to choose one item from a list of options. If there is enough vertical or horizontal space consider a radioGroup as alternative. If there are lots of option, consider using a typeAhead instead.

You have to pass a store as value in order to handle the selected value, and the events will be connected automatically.

Basic usage:

val myOptions = listOf("black", "red", "yellow")
val selectedItem = storeOf(myOptions[0]) // preselect "red"
selectField (items = myOptions, value = selectedItem) {
}

See also

Parameters

styling

a lambda expression for declaring the styling as fritz2's styling DSL

items

a list of all available options

value

for backing up the preselected item and reflecting the selection automatically.

baseClass

optional CSS class that should be applied to the element

id

the ID of the element

prefix

the prefix for the generated CSS class resulting in the form $prefix-$hash

build

a lambda expression for setting up the component itself. Details in SelectFieldComponent