Field

fun <T> Form<T>.Field(selector: (T) -> TextFieldState, validator: FieldValidator<CharSequence>? = null, name: FieldName? = null, dependsOn: FieldNames? = null, enabled: Boolean = true, render: @Composable (FormTextField) -> Unit)(source)

Creates a form text field with validation and state management for TextFieldState.

This function creates a text field that integrates with Compose's TextFieldState API, providing automatic validation of the text content and seamless integration with modern text field components.

Usage:

form.Field(
selector = { it.emailState },
validator = FieldValidator {
notBlank { "Email is required" }
email { "Must be a valid email" }
},
render = { field ->
TextField(
state = field.state,
isError = field.hasError,
modifier = Modifier.onFocusChanged { state ->
field.handleFocus(state.isFocused)
}
)
}
)

Parameters

T

The type of the form data.

selector

A function that extracts the TextFieldState from the form data.

validator

Optional validator for TextFieldState.text.

name

Optional custom name for the field. If null, an auto-generated name is used.

dependsOn

Optional list of field names this field depends on for validation.

enabled

Whether the field is enabled for input.

render

The composable content that renders the field UI.


fun <T, S> Form<T>.Field(selector: (T) -> TextFieldState, adapter: TextFieldStateAdapter<S>, validator: FieldValidator<S>? = null, name: FieldName? = null, dependsOn: FieldNames? = null, enabled: Boolean = true, render: @Composable (FormTextField) -> Unit)(source)

Creates a form text field with type adaptation, validation, and state management.

This overload allows you to use a TextFieldStateAdapter to convert the text content to a different type for validation. This is useful when you need to validate the text as a specific data type (e.g., validating numeric input, dates, or custom formats).

Usage:

form.Field(
selector = { it.ageState },
adapter = IntTextFieldStateAdapter(),
validator = FieldValidator<Int> {
min(0) { "Age must be non-negative" }
max(150) { "Age must be realistic" }
},
render = { field ->
TextField(
state = field.state,
isError = field.hasError,
modifier = Modifier.onFocusChanged { state ->
field.handleFocus(state.isFocused)
}
)
}
)

Parameters

T

The type of the form data.

S

The type used for validation after adaptation.

selector

A function that extracts the TextFieldState from the form data.

adapter

The adapter that converts text content to the validation type.

validator

Optional validator for the adapted type (S).

name

Optional custom name for the field. If null, an auto-generated name is used.

dependsOn

Optional list of field names this field depends on for validation.

enabled

Whether the field is enabled for input.

render

The composable content that renders the field UI.


fun Form<TextFieldState>.Field(validator: FieldValidator<CharSequence>? = null, name: FieldName? = null, enabled: Boolean = true, render: @Composable (FormTextField) -> Unit)(source)

Creates a field for a TextFieldState-based form with direct text validation.

This specialized Field function is designed for forms where the entire form data is a single TextFieldState. It provides a streamlined API for single-field forms, eliminating the need for selector and updater functions since the form data itself is the TextFieldState.

Parameters

validator

Optional validator for TextFieldState.text.

name

Optional custom name for the field. If null, an auto-generated name is used.

enabled

Whether the field is enabled for input.

render

The composable content that renders the field UI.


fun <S> Form<TextFieldState>.Field(adapter: TextFieldStateAdapter<S>, validator: FieldValidator<S>? = null, name: FieldName? = null, enabled: Boolean = true, render: @Composable (FormTextField) -> Unit)(source)

Creates a field for a TextFieldState-based form with type adaptation and validation.

This overload allows you to use a TextFieldStateAdapter to convert the text content to a different type for validation. This is useful for single-field forms that need to validate the input as a specific data type while maintaining the simplicity of a TextFieldState-only form.

Parameters

S

The type used for validation after adaptation.

adapter

The adapter that converts text content to the validation type.

validator

Optional validator for the adapted type (S).

name

Optional custom name for the field. If null, an auto-generated name is used.

enabled

Whether the field is enabled for input.

render

The composable content that renders the field UI.