rememberField
Creates and remembers a form text field control with validation and state management.
This function creates a FormTextField control that can be used to manage text 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.emailState },
validator = FieldValidator {
notBlank { "Email is required" }
email { "Must be a valid email" }
}
)
TextField(
state = emailField.state,
isError = field.hasError,
modifier = Modifier.onFocusChanged { state ->
emailField.handleFocus(state.isFocused)
}
)
Return
A FormTextField control object for managing the text field state and interactions.
Parameters
The type of the form data.
A function that extracts the TextFieldState from the form data.
Optional validator for TextFieldState.text.
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 text field control with type adaptation, validation, and state management.
This function creates a FormTextField control with type adaptation capabilities, allowing you to convert the text content to a different type for validation. Unlike the Field composable functions, this returns the control object directly without rendering UI, providing maximum flexibility for custom text field implementations.
Usage:
val ageField = form.rememberField(
selector = { it.ageState },
adapter = IntTextFieldStateAdapter(),
validator = FieldValidator<Int> {
min(0) { "Age must be non-negative" }
max(150) { "Age must be realistic" }
}
)
Column {
TextField(
state = ageField.state,
isError = field.hasError,
modifier = Modifier.onFocusChanged { state ->
ageField.handleFocus(state.isFocused)
}
)
}
Return
A FormTextField control object for managing the text field state and interactions.
Parameters
The type of the form data.
The type used for validation after adaptation.
A function that extracts the TextFieldState from the form data.
The adapter that converts text content to the validation type.
Optional validator for the adapted 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.