rememberField
Creates and remembers a form field control with validation and state management.
This function creates a FormField control that can be used to manage field state and interactions. Unlike the Field composable functions, this returns the control object directly without rendering UI, allowing for more flexible usage patterns.
Usage:
val emailField = form.rememberField(
selector = { it.email },
updater = { copy(email = it) },
validator = FieldValidator {
notBlank { "Email is required" }
email { "Must be a valid email" }
}
)
TextField(
value = emailField.value,
onValueChange = emailField::onValueChange,
isError = emailField.hasError
)
Return
A FormField control object for managing the field state and interactions.
Parameters
The type of the form data.
The type of the field value.
A function that extracts the field value from the form data.
A function that updates the form data with a new field value.
Optional validator for the field value.
Optional custom name for the field. If null, an auto-generated name is used.
Optional list of field names this field depends on for validation.
Whether the field is enabled for input.
Creates and remembers a form field control with type adaptation, validation, and state management.
This function creates a FormField control with type adaptation capabilities, allowing you to convert between the stored value type (V), validation target type (S), and input type (U). Unlike the Field composable functions, this returns the control object directly without rendering UI, providing maximum flexibility for custom field implementations.
Usage:
val ageField = form.rememberField(
selector = { it.age },
updater = { copy(age = it) },
adapter = IntStringAdapter(),
validator = FieldValidator<Int> {
min(0) { "Age must be non-negative" }
max(150) { "Age must be realistic" }
}
)
TextField(
value = ageField.value, // String type from adapter
onValueChange = ageField::onValueChange,
isError = ageField.hasError
)
Return
A FormField control object for managing the field state and interactions.
Parameters
The type of the form data.
The type of the field value as stored in the form data.
The type used for validation.
The type used for input/display.
A function that extracts the field value from the form data.
A function that updates the form data with a new field value.
The type adapter that converts between V, S, and U types.
Optional validator for the validation target type (S).
Optional custom name for the field. If null, an auto-generated name is used.
Optional list of field names this field depends on for validation.
Whether the field is enabled for input.