This Friday: Hear from Sanity + Vercel experts on AI and better personalization in e-commerce

Conditional field with 3 choices in sibling momentType field

6 repliesLast updated: Dec 1, 2025

how would i use the new conditional field if there are 3 choices in a sibling? i have a field called
momentType
that has choices of
image, video and text
.
AI Update

Based on your momentType field with three choices (image, video, and text), you can use conditional fields to show/hide related fields for each type. Here's how to implement it:

{
  name: 'momentType',
  type: 'string',
  title: 'Moment Type',
  options: {
    list: [
      {title: 'Image', value: 'image'},
      {title: 'Video', value: 'video'},
      {title: 'Text', value: 'text'}
    ]
  }
},
// Image-specific fields
{
  name: 'imageField',
  type: 'image',
  title: 'Image',
  hidden: ({parent}) => parent?.momentType !== 'image'
},
// Video-specific fields
{
  name: 'videoUrl',
  type: 'url',
  title: 'Video URL',
  hidden: ({parent}) => parent?.momentType !== 'video'
},
// Text-specific fields
{
  name: 'textContent',
  type: 'text',
  title: 'Text Content',
  hidden: ({parent}) => parent?.momentType !== 'text'
}

The key is using the hidden property with a callback function that receives parent as a parameter. The parent object contains the values of sibling fields in the same object or document. By checking parent?.momentType, you can show/hide fields based on the selected choice.

Important considerations:

{
  name: 'imageField',
  type: 'image',
  hidden: ({parent}) => parent?.momentType !== 'image',
  validation: (Rule) =>
    Rule.custom((currentValue, {parent}) => {
      return parent?.momentType === 'image' && !currentValue
        ? 'Image is required when moment type is image'
        : true
    })
}

For more details on conditional fields, check out the official documentation and this helpful guide on conditional fields in arrays.

Show original thread
6 replies

Was this answer helpful?

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.

Related contributions