Field
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
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.
The composable content that renders the field UI.
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
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.
The composable content that renders the field UI.
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
Optional validator for TextFieldState.text.
Optional custom name for the field. If null, an auto-generated name is used.
Whether the field is enabled for input.
The composable content that renders the field UI.
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
The type used for validation after adaptation.
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.
Whether the field is enabled for input.
The composable content that renders the field UI.