FormField

A control interface for managing individual form field state and interactions.

This interface provides access to field state (value, validation errors, focus state) and methods for handling user interactions (value changes, focus events, validation triggers). It serves as the bridge between the form field UI and the underlying form state management.

Usage:

form.Field(
selector = { it.email },
updater = { copy(email = it) },
render = { field ->
TextField(
value = field.value,
onValueChange = field::onValueChange,
isError = field.hasError,
modifier = Modifier.onFocusChanged { state ->
field.handleFocus(state.isFocused)
}
)
}
)

Parameters

V

The type of the field value.

Properties

Link copied to clipboard
abstract val error: FieldError

The current validation error for this field, if any.

Link copied to clipboard

Whether the field currently has any validation errors.

Link copied to clipboard
abstract val isEnabled: Boolean

Whether the field is enabled for user interaction.

Link copied to clipboard
abstract val isFocused: Boolean

Whether the field currently has focus.

Link copied to clipboard
abstract val isTouched: Boolean

Whether the field has been touched (focused and then blurred) by the user.

Link copied to clipboard
abstract val name: FieldName

The unique name identifier for this field within the form.

Link copied to clipboard
abstract val value: V

The current value of the field.

Functions

Link copied to clipboard
abstract fun handleFocus(hasFocus: Boolean)

Handles focus state changes by calling onFocus() or onBlur() as appropriate.

Link copied to clipboard
abstract fun onBlur()

Marks the field as blurred (not focused) and touched.

Link copied to clipboard
abstract fun onFocus()

Marks the field as focused.

Link copied to clipboard
abstract fun onValueChange(value: V)

Updates the field value and triggers validation if configured.

Link copied to clipboard
abstract fun trigger(mode: FieldValidationMode): Boolean

Manually triggers validation for this field with the specified mode.