Adding a field to select multiple strings from a fixed list in Sanity.io schema.
You're on the right track! For selecting multiple strings from a fixed list in Sanity, you'll want to use an array of strings with the list option. Here's how to set it up:
{
name: 'selectedOptions',
title: 'Select Options',
type: 'array',
of: [{
type: 'string'
}],
options: {
list: [
{title: 'Option A', value: 'A'},
{title: 'Option B', value: 'B'},
{title: 'Option C', value: 'C'},
{title: 'Option D', value: 'D'},
{title: 'Option E', value: 'E'}
]
}
}This gives you a nice multi-select interface in the Studio where users can pick multiple values from your predefined list. The data will be stored as an array like ["A", "C", "E"].
Key points:
- The
type: 'array'withof: [{type: 'string'}]creates an array that holds strings - The
options.listproperty on the array field (not the string type inside it) provides the predefined values - You can use simple string values in the list (
['A', 'B', 'C']) or objects withtitleandvalueproperties for better labels
If you want the list to appear as checkboxes instead of a dropdown, you can add layout: 'tags' or layout: 'grid' to the options:
options: {
list: [...],
layout: 'tags' // or 'grid'
}This is covered in the Array type documentation under the "predefined strings" example. The array field's copy/paste functionality also works great with this setup if you need to duplicate selections across documents!
Sanity β Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.