How AI is powering better personalization in e-commerce [with Vercel]. Sign up now →

How to set boolean field default value to true in Sanity Studio?

6 repliesLast updated: Nov 29, 2025

😟How do I make a boolean true on my sanity studio? For example, when a new document is created I want the boolean to be checked true. I used
initialValue: true
but when I created a new document it wasn't checked true by default.
AI Update

I understand the frustration! The good news is that initialValue: true is the correct approach for setting a boolean field to default to true, but there's a common gotcha that might be affecting you.

When you add or change initialValue on a field, it only applies to documents created after that change. If you're testing on an existing document (even one you just created before adding the initialValue), it won't retroactively apply the default value. You need to create a brand new document after adding the initialValue to your schema.

Here's the correct syntax for a boolean field with a default value:

defineField({
  name: 'isPublished',
  type: 'boolean',
  title: 'Published',
  initialValue: true
})

Troubleshooting steps:

If you need more complex logic for setting initial values (like checking user context or fetching data), you can also use a function:

defineField({
  name: 'isPublished',
  type: 'boolean',
  title: 'Published',
  initialValue: () => true
})

The field-level initialValue approach should work for your use case. Just remember to test with a freshly created document after making the schema change!

Show original thread
6 replies

Was this answer helpful?

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.

Related contributions