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
Schema type reference for the URL type.
Text
Schema type reference for the Text type.
Boolean
Schema type reference for expressing truthy values.
Date
Schema type reference for the Date type.
Geopoint
Schema type reference for the geopoint type.
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
Schema type reference for the File type.
Number
Schema type reference for the Number type.
Datetime
The schema type for expressing an exact date and time.
- Previous page
Conditional fields
How to make fields hidden or read-only based on other fields' values or on information about the current user.