How to set a boolean field to true by default in Sanity Studio.
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:
Make sure your Studio has reloaded after changing the schema. Sometimes you need to restart your dev server or refresh the browser.
Create a completely new document (not one you started before adding
initialValue). The initial value only applies to documents created after the schema change.Check for Initial Value Templates - If you have Initial Value Templates configured in your
sanity.config.ts, they can override field-levelinitialValuesettings. Templates take precedence over schema-level defaults.Verify your schema syntax - Make sure you're using
initialValue(notdefaultValueor another property name).
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!
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.