Skip to main content

ChoicesField

Displays an enum value as a colored chip.

Use it for a field with a fixed set of values. For a link to another record reach for SchemaReferenceField instead.

Example​

const statusChoices = [
{value: 'draft', label: 'Draft', color: 'default'},
{value: 'published', label: 'Published', color: 'success'},
{value: 'archived', label: 'Archived', color: 'error'},
];

<ChoicesField source="status" choices={statusChoices} />

Props​

On top of its own choices, the component accepts the shared field props.

NameTypeDefaultDescription
source (required)string—Name of the field on the record
choices (required)Choices—Enum values: {value, label, color?, icon?}
labelstring | ReactElement | falselabel from the schemafalse hides the label
emptyTextstring—Text shown when the value is empty
recordRaRecordrecord from contextRenders a record other than the one in context
iconsKeystring—Key into the iconsMap on SchemaAdmin, used to give the chip an icon

SchemaChoicesField is the wrapper the schema mounts: choices comes from the field's enum and iconsKey from options.choices.iconsKey.

Chip color comes from color on the enum entry; inherit behaves as default. When the displayed value's entry carries an icon, the component renders an icon chip instead of a plain one.

In a list the chip is truncated to the column width, so a long label does not push the column open.

Schema mapping​

The component is picked for a field with format: "choices":

{"name": "status", "type": "string", "format": "choices",
"enum": [{"value": "draft", "label": "Draft", "color": "default"}]}

The enum is derived from choices on the model field:

class Product(models.Model):
status = models.CharField(max_length=16, choices=ProductStatus.choices)

See also​