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
List of accepted values. This defines all possible options that can be selected.
Maximum number of values that can be selected. Set to 1 (or less) for single-select mode. Set to > 1 for multi-select mode.
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:
Append values
Prepend values
Remove values
// Add values to the end of the selection
record . Set ( "roles+" , [] string { "editor" , "viewer" })
// Before: ["admin", "moderator"]
// After: ["admin", "moderator", "editor", "viewer"]
Go examples
Single select
Multi select
With modifiers
Priority/category
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" )
field := & core . SelectField {
Name : "tags" ,
Required : false ,
MaxSelect : 5 ,
Values : [] string { "tech" , "business" , "science" , "arts" , "sports" },
}
collection . Fields . Add ( field )
// Set multiple values
record . Set ( "tags" , [] string { "tech" , "business" })
field := & core . SelectField {
Name : "permissions" ,
MaxSelect : 10 ,
Values : [] string {
"read" , "write" , "delete" ,
"admin" , "moderator" , "editor" ,
},
}
collection . Fields . Add ( field )
// Set initial values
record . Set ( "permissions" , [] string { "read" })
// Add more permissions
record . Set ( "permissions+" , [] string { "write" , "delete" })
// Remove a permission
record . Set ( "permissions-" , "delete" )
// Result: ["read", "write"]
field := & core . SelectField {
Name : "priority" ,
Required : true ,
MaxSelect : 1 ,
Values : [] string { "low" , "medium" , "high" , "critical" },
}
collection . Fields . Add ( field )
record . Set ( "priority" , "high" )
Database column type
The column type varies based on whether it’s single or multi-select:
Single select (maxSelect <= 1)
Multi select (maxSelect > 1)
Common use cases
Status field
User roles
Content categories
Size options
field := & core . SelectField {
Name : "status" ,
Required : true ,
MaxSelect : 1 ,
Values : [] string { "pending" , "approved" , "rejected" },
}
Querying select fields
Single select query
Multi select query
// 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 []