ChoicesInput
Collects one value of an enum from a dropdown, with an optional icon per option.
Use it for a fixed set of values that comes with the schema. To pick a record of another resource use SchemaReferenceInput, which loads its options from the backend.
Example
const statusChoices = [
{value: 'draft', label: 'Draft', color: 'default'},
{value: 'published', label: 'Published', color: 'success'},
{value: 'archived', label: 'Archived', color: 'error'},
];
<ChoicesInput source="status" choices={statusChoices} />
Props
On top of choices the component accepts the shared input props and
React Admin's SelectInput props.
| Name | Type | Default | Description |
|---|---|---|---|
source (required) | string | — | Name of the field in the form record |
choices (required) | Choices | — | Enum values: {value, label, color?, icon?} |
label | string | ReactElement | false | label from the schema | false hides the label |
validate | Validator | Validator[] | from the schema | React Admin validators |
iconsKey | string | — | Key into the iconsMap on SchemaAdmin, used to give each option an icon |
The schema layer renders this component directly: choices comes from the field's enum and
iconsKey from options.choices.iconsKey.
caution
Unlike ChoicesField, the input ignores the color of an
enum entry — the dropdown shows an icon and a label, not a colored chip.
An array of enum values renders as a multi-select instead — see SchemaArrayInput.
Schema mapping
A field with format: "choices" and an enum:
{"name": "status", "type": "string", "format": "choices",
"enum": [{"value": "draft", "label": "Draft"}, {"value": "published", "label": "Published"}]}
- Python
- Ruby
class ProductStatus(models.TextChoices):
DRAFT = "draft", _("Draft")
PUBLISHED = "published", _("Published")
ARCHIVED = "archived", _("Archived")
class Product(models.Model):
status = models.CharField(max_length=16, choices=ProductStatus.choices, default=ProductStatus.DRAFT)
See also
- ChoicesField — the display counterpart
- SchemaArrayInput — selecting several enum values at once