Selection Fields
Selection fields allow administrators to choose one or more values from predefined options.
In most cases, KraftAdmin automatically infers the appropriate selection component from the property type. You can also explicitly configure the component using inputType.
Automatic Type Inference
KraftAdmin automatically maps common types to selection components.
No additional configuration is required.
Select
Use a dropdown when only one value should be selected.
enum class Status {
DRAFT,
REVIEW,
PUBLISHED
}
@KraftAdminField
var status: Status = Status.DRAFT Or explicitly specify the component.
@KraftAdminField(
inputType = FormInputType.SELECT
)
var status: Status = Status.DRAFT Multi Select
Allows selecting multiple values.
enum class Permission {
READ,
WRITE,
DELETE
}
@KraftAdminField(
inputType = FormInputType.MULTI_SELECT
)
var permissions: Set<Permission> = emptySet() The administrator can choose multiple options from a searchable list.
Radio Buttons
Radio buttons are ideal when there are only a few available choices.
@KraftAdminField(
inputType = FormInputType.RADIO
)
var status: Status = Status.DRAFT Unlike a Select, every available option is immediately visible.
Checkbox
Boolean properties automatically render as checkboxes.
@KraftAdminField
var enabled: Boolean = true Equivalent explicit configuration:
@KraftAdminField(
inputType = FormInputType.CHECKBOX
)
var enabled: Boolean = true Validation
Selection fields support every standard field option.
@KraftAdminField(
required = true,
readonly = false,
placeholder = "Choose a status"
) | Property | Description |
|---|---|
required | Selection must not be empty |
readonly | Displays but cannot be changed |
placeholder | Default placeholder text |
label | Custom display label |
group | Form section grouping |
Best Practices
- Use Select for lists with many options.
- Use Radio when there are fewer than five choices.
- Use Checkbox only for boolean values.
- Use Multi Select when multiple values are expected.
- Prefer automatic type inference unless a different UI is desired.