Set default value for string list options in Sanity schema
Yes, you can control both the blank option and set a default value for a string field with a list in options!
Avoiding the blank option
When you use a list option with layout: 'dropdown', Sanity shows a blank option by default. To avoid this, you have two options:
Use radio buttons instead: Set
layout: 'radio'in your options. This removes the blank dropdown option entirely.Set an initial value: Use the
initialValueproperty to pre-select a specific option.
Setting a default selected option
Use the initialValue property on your field to set which option is selected by default:
{
title: 'Genre',
name: 'genre',
type: 'string',
options: {
list: [
{title: 'Sci-Fi', value: 'sci-fi'},
{title: 'Western', value: 'western'}
],
layout: 'dropdown' // or 'radio'
},
initialValue: 'sci-fi' // Sets Sci-Fi as the default
}Complete example
Here's a field configuration that avoids the blank option and sets a default:
{
title: 'Genre',
name: 'genre',
type: 'string',
options: {
list: [
{title: 'Sci-Fi', value: 'sci-fi'},
{title: 'Western', value: 'western'},
{title: 'Drama', value: 'drama'}
],
layout: 'radio' // No blank option with radio buttons
},
initialValue: 'sci-fi' // Sci-Fi selected by default
}The initialValue works with both dropdown and radio layouts. When using radio buttons, the specified value will be pre-selected. With dropdowns, it will show that value instead of a blank option when creating new documents.
You can find more details in the string type documentation and the initial values guide.
Show original thread22 replies
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.