initialValue for boolean field not working in Sanity Studio
I understand the frustration! This is actually expected behavior in Sanity Studio. The initialValue property only applies when a document is first created - it doesn't retroactively apply to existing documents or even to fields in documents that are already open.
Here are the key things to understand:
How initialValue works:
Field-level initialValue in your schema only sets the value when:
- A brand new document is created
- The field hasn't been touched yet
If you're testing on an existing document or a document that's already been created, you won't see the initial value applied.
To set a boolean field to true by default:
defineField({
name: 'approved',
type: 'boolean',
initialValue: true
})This should work, but as documented, you need to:
- Create a completely new document - not edit an existing one
- Make sure you haven't already interacted with that field (even unchecking a checkbox counts as setting a value)
Common gotchas:
- If you opened a draft before adding the
initialValue, that draft won't have it - If you're testing by refreshing the page on an existing document, it won't apply
- The
initialValueis set on the client side when the document form initializes, so it won't show up in existing documents in your dataset
To test it properly:
- Make sure your schema changes are saved and Studio has reloaded
- Create a brand new document (click "Create" â select your document type)
- The boolean should be checked immediately when the form loads
If you need more complex initialization logic or want to set values based on context (like the current user or parent document), you can use Initial Value Templates in your sanity.config.ts file instead.
Hope this clears things up! Let me know if you're still seeing issues after creating a fresh document.
Show original thread5 replies
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.