Skip to main content
The select field stores one or more string values from a predefined list of options. It supports both single-select and multi-select modes, with special setter modifiers for manipulating selections.

Configuration options

values
[]string
required
List of accepted values. This defines all possible options that can be selected.
maxSelect
int
default:"1"
Maximum number of values that can be selected. Set to 1 (or less) for single-select mode. Set to > 1 for multi-select mode.
required
bool
default:"false"
When true, requires at least one value to be selected.

Validation rules

The select field validates:
  • Values: All selected values must be in the predefined values list
  • Max select: Number of selected values cannot exceed maxSelect
  • Required: If enabled, at least one value must be selected

Single vs multi-select

The field behavior changes based on maxSelect:
  • maxSelect <= 1: Single-select mode (value is a string)
  • maxSelect > 1: Multi-select mode (value is a string array)

Special setter modifiers

The select field supports several modifiers for manipulating selections:
// Add values to the end of the selection
record.Set("roles+", []string{"editor", "viewer"})
// Before: ["admin", "moderator"]
// After:  ["admin", "moderator", "editor", "viewer"]

Go examples

import "github.com/pocketbase/pocketbase/core"

field := &core.SelectField{
    Name:      "status",
    Required:  true,
    MaxSelect: 1,
    Values:    []string{"draft", "published", "archived"},
}

collection.Fields.Add(field)

// Set single value
record.Set("status", "published")

Database column type

The column type varies based on whether it’s single or multi-select:
TEXT DEFAULT '' NOT NULL

Common use cases

field := &core.SelectField{
    Name:      "status",
    Required:  true,
    MaxSelect: 1,
    Values:    []string{"pending", "approved", "rejected"},
}

Querying select fields

// Find records with specific status
records, err := app.FindRecordsByFilter(
    "articles",
    "status = 'published'",
    "-created",
    10,
    0,
)

Best practices

  • Keep the values list concise and meaningful
  • Use single-select for mutually exclusive options (status, priority, etc.)
  • Use multi-select for non-exclusive categorization (tags, permissions, etc.)
  • Consider the UX implications of large values lists (use relation fields for large datasets)
  • Use + and - modifiers in multi-select mode for cleaner code
  • Selections are stored in order, duplicates are automatically removed

Zero value

  • Single-select: Empty string ""
  • Multi-select: Empty array []