✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Making fields required in Sanity schema using a validation rule

1 replies
Last updated: May 23, 2023
Is there any way to make fields in your schema Required by default? 90%+ or so of our fields should be required, and we’d rather do something like
Rule.optional()
for ones that are not
May 23, 2023, 7:19 PM
No, but since the schema is just javascript, you can programmatically add the
required
validation rule by using a function to assign it to the object containing your schema.
Not quite default, but not too much overhead!
May 23, 2023, 7:49 PM

Sanity– build remarkable experiences at scale

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

Was this answer helpful?