Conditional Fields
Published: August 26, 2021
A lot of you have been waiting for this for a while: A way to show and hide fields based on the value of some other field. The wait is over! In this release of the Sanity Studio the hidden
field has been upgraded to take a callback function.
export default {
type: 'object',
name: 'dropdownExample',
fields: [
{
name: 'kind',
type: 'string',
options: {list: ['foo', 'bar', 'baz']},
},
{
name: 'fooOptions',
type: 'object',
hidden: ({parent}) => !(parent?.kind === 'foo'),
fields: [/* ... */],
},
{
name: 'barOptions',
type: 'number',
hidden: ({parent}) => !(parent?.kind === 'bar'),
fields: [/* ... */],
},
],
}

Get more code examples and read more about the details in our docs.
Related documentation
Schema
A schema describes the types of documents and fields editors may author in a Sanity Studio workspace.
Slug
A schema type for slugs is typically used to create unique URLs.
Object
Schema type to create custom types to use in a document.
URL
Text
Boolean
Date
Geopoint
String
A schema type for strings and a selectable lists of strings.
Image
Schema type for uploading, selecting, and editing images.
Reference
A schema type for referencing other documents.
Array
Schema type for arrays of other types.
Block
Schema type for block which provides a rich text editor for block content.
File
Number
Datetime
The schema type for expressing an exact date and time.
Conditional fields