Discussion on setting initial values for an array field in Sanity, including suggestions for using a custom input component and reviewing the content model.
I can see the confusion here! You're mixing up two different concepts in Sanity's array field configuration. The options.list property and initialValue serve completely different purposes, and your code is trying to use them incorrectly together.
What options.list actually does:
The options.list property is used with string fields (not array fields) to create a dropdown/radio/checkbox selector. When you put options.list on an array field, it doesn't do what you're expecting. Here's the correct usage for a string field with predefined options:
{
type: 'string',
name: 'myOption',
title: 'My Option',
options: {
list: [
{value: 'option1', title: 'Option 1'},
{value: 'option2', title: 'Option 2'}
]
}
}What you probably want:
Based on your code, you likely want one of these scenarios:
1. Array of strings with initial values:
{
type: 'array',
name: 'options',
title: 'Opzioni',
of: [{type: 'string'}],
initialValue: ['myValue', 'anotherValue'] // Just strings, not objects
}2. Array of objects with value/title structure:
{
type: 'array',
name: 'options',
title: 'Opzioni',
of: [{
type: 'object',
fields: [
{name: 'value', type: 'string'},
{name: 'title', type: 'string'}
]
}],
initialValue: [
{value: 'myValue', title: 'myTitle', _key: 'unique-key-1'}
]
}Note: Array items need a _key property for tracking. Sanity usually generates these automatically, but you can provide them in initialValue.
3. String field with predefined options (most common for dropdowns):
{
type: 'string',
name: 'selectedOption',
title: 'Opzione',
options: {
list: [
{value: 'myValue', title: 'myTitle'},
{value: 'otherValue', title: 'Other Title'}
]
},
initialValue: 'myValue' // Just the value, not an object
}The array field documentation explains that arrays are for orderable collections where you define what types can go inside using the of property. The options.list pattern simply doesn't apply to array fields - it's specifically for constraining string field values to a predefined set of choices.
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.