Field
Creates a form field with validation and state management.
This function creates a form field that automatically handles value changes, validation, and state management. The field integrates with the parent form and participates in form-wide validation.
Usage:
form.Field(
selector = { it.email },
updater = { copy(email = it) },
validator = FieldValidator {
notBlank { "Email is required" }
email { "Must be a valid email" }
},
render = { field ->
TextField(
value = field.value, // String type
onValueChange = field::onValueChange,
isError = field.hasError
)
}
)
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.
The composable content that renders the field UI.
Creates a form field with type adaptation, validation, and state management.
This overload allows you to use a type adapter to convert between the stored value type (V), validation target type (S), and input type (U). This is useful when you need to validate or display a field value in a different format than how it's stored.
Usage:
form.Field(
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" }
},
render = { field ->
TextField(
value = field.value, // String type
onValueChange = field::onValueChange
)
}
)
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.
The composable content that renders the field UI.