Roboto Studio
The best editorial experiences on the web
This validation can be used if you have two fields and you require one or the other to be filled
export default {
name: "someDocument",
title: "Some document",
type: "document",
fields: [
{
name: "videoUrl",
title: "Video url",
type: "string",
validation: (Rule) =>
Rule.custom((field, context) =>
context.document.image === undefined && field === undefined
? "Either Video url or Image must have a value"
: true
),
},
{
name: "image",
title: "Image",
type: "image",
validation: (Rule) =>
Rule.custom((field, context) =>
context.document.videoUrl === undefined && field === undefined
? "Either Video url or Image must have a value"
: true
),
},
],
};
This regularly appears within websites where you can have either a video or an image for the header of the page. This allows you to validate to ensure you have one or the other.
The best editorial experiences on the web
Create Next.js redirects, directly inside of your Sanity Studio with validation
Go to Next.js Redirect schema with validationThinking about getting started with AI? Well we're just going to share our latest and greatest prompt so you don't have to do the hard work
Go to Cursor PromptOn the fly form generation with Sanity & Formspark
Go to Sanity & Formspark Form GeneratorIf you're looking to mockup portable text in Storybook without a Sanity backend, this is the schema you're looking for
Go to Portable Text Mock ContentContent operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store