Conditional Fields - Showing and Hiding Fields Based on Field Values

6 replies
Last updated: Sep 14, 2021
how would i use the new conditional field if there are 3 choices in a sibling? i have a field called
that has choices of
image, video and text
Sep 14, 2021, 7:32 PM
So you want a different field to be shown/hidden based on the value of
Sep 14, 2021, 7:36 PM
yes… each choice has a single field (image, video, text)
Sep 14, 2021, 7:37 PM
here’s what i’ve got so far, not sure if it will work since i’m still refactoring

hidden: ({parent}) => parent?.momentType. !== 'imageType' || parent?.momentType !== 'videoType'
Sep 14, 2021, 7:44 PM
That looks good other than the
after the first
You should also be able to do
hidden: ({parent}) => !(parent?.momentType === 'textType')
Sep 14, 2021, 7:47 PM
ahh, that’s much more concise
Sep 14, 2021, 7:48 PM
Sep 14, 2021, 7:48 PM – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in