
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou can make a dropdown string field required by adding a validation rule to your field definition. Here's how:
defineField({
name: 'category',
type: 'string',
options: {
list: [
{title: 'Technology', value: 'tech'},
{title: 'Design', value: 'design'},
{title: 'Business', value: 'business'}
]
},
validation: (rule) => rule.required()
})The key is adding the validation property with rule.required(). This will prevent the document from being published until a value is selected from the dropdown.
You can also customize the error message if you want:
validation: (rule) => rule.required().error('Please select a category')This works the same way for any string field with a dropdown (created using the options.list property). The validation system happens client-side in the Studio and will show an error indicator on the field if left empty.
Keep in mind that validation only runs in the Studio - if you're creating or updating documents via the API directly, you'll need to implement server-side validation separately.
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.
Content 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