Browse all documentation

Select field

Add a dropdown for one choice or a multi-select for several choices.

Use field.Select when authors must choose from a fixed list of options. It renders a dropdown for one choice. Use field.MultiSelect for several choices. Generated TypeScript narrows input and output to the configured string values instead of a free-form string.

In the admin

An open multiple Status select in the Ridu admin showing In review and Published as selected choices.

The menu displays labels; stored and generated values use the configured option values.

Add a dropdown

content/posts.go
field.Select("status", "draft", "review", "published").Default("draft")

Pass strings directly for generated labels: "in-review" displays as “In review”, while the stored value remains "in-review". Use .Options(...) with field.Option for custom labels or translations:

content/posts.go
field.Select("visibility").Options(
  field.Option{
    Value:             "public",
    Label:             "Everyone",
    LabelTranslations: map[string]string{"fr": "Tout le monde"},
  },
  field.Option{Value: "members", Label: "Signed-in members"},
)

.Options(...) replaces the entire option list, including any constructor values. Omit an option’s Label to generate it from Value. Reuse a typed slice with .Options(options...), where options is a []field.Option; string slices work in the constructor with values....

Values are stable data; labels and LabelTranslations are presentation. Changing members to registered is a data/API migration, while changing its label is not.

Configuration

Constructor or method What it controls
field.Select(name, values...) Stores one configured string and renders a dropdown.
field.MultiSelect(name, values...) Stores an ordered list of configured strings and renders a multi-select.
.Options(options...) Replaces inferred options with explicit values, labels, and label translations.
.Required() Requires one value, or a non-empty list for MultiSelect.
.Default(...) / .DefaultFrom(callback) Supplies the initial choice or choices when a new scope omits the field.
.Localized() Stores a separate choice or list for each configured content locale.
.Unique() / .Index() Available on singular Select; enforces uniqueness or adds a query index.
.Validate(...), .LiveValidate(...), .Access(...), .Hooks(...) Adds application checks, authorization, and lifecycle behavior.

Allow several choices

content/posts.go
field.MultiSelect("channels", "web", "email", "social").Default("web", "email")

Multi-selects store an ordered list of unique configured values. Its Default method accepts several strings. Radio cannot be multiple.

Choose the initial selection

Use .Default("draft") for a fixed choice or .DefaultFrom(callback) to choose on the server. For example, a callback could choose a review status from the signed-in user’s role. Select and Radio callbacks return operation.Value[string]; MultiSelect callbacks return operation.Value[[]string]. Return option values such as "draft", rather than display labels.

Defaults fill omitted selections; they preserve an author’s explicit selection or empty input. All returned options must be declared on the field. See Set default field values for a complete callback and when it runs.

Validate and translate choices

At least one non-empty unique option is required. Defaults must be in the option list. Select also supports Required, localization, indexing/uniqueness where appropriate, conditions, and common admin options. Localizing the field stores different selected values per content locale; translating option labels alone uses Option.LabelTranslations.

Filter by choice

Query a single choice with equals, notEquals or in. A multi-select is filtered by membership: { audiences: { in: ['editors', 'reviewers'] } } matches a document that selected either option, and query.Not(query.In("audiences", "editors")) excludes those that selected editors. Equality, contains and sorting are unavailable for multi-selects and fail with an unsupported_operator or unsupported_path issue. The admin list offers is any of and is none of with the field’s options. See Filter by membership.

Common mistakes

  • Do not use labels as API values. Submit the exact Value string.
  • Adding a choice is additive; removing or renaming a value requires a migration for existing data.
  • Use Relationship when choices are managed documents rather than a fixed list compiled into config.

See field.Select, SelectField.Options, and field.MultiSelect.