How to Make a Field Mandatory or Required in the Studio

1 replies
Last updated: May 10, 2021
In sanity studio how do you make a field required so that they cant leave it blank or make a default entry, eg the slug field is automatically generated using the title
May 10, 2021, 8:54 AM
Hi
user V
! You can do this by adding a required validation rule to the field, here is an example:
    {
      title: 'slug',
      name: 'slugName',
      type: 'slug',
      validation: (Rule) => Rule.required(),
    },
Here is the documentation on validation for further context:
https://www.sanity.io/docs/validation Also, here is documentation for the slug field that provides the validation and options available specifically for slugs:
https://www.sanity.io/docs/slug-type I hope this helps!
May 10, 2021, 2:46 PM

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.

Was this answer helpful?