🗓️ Everything *[NYC] is back. A free gathering for AI builders. Sept 9 →

Toggle input initialValue not setting to true in Sanity schema

2 repliesLast updated: Dec 2, 2025

hey everyone! i'm having a strange issue with my schema where i'm trying to set the initial value of a toggle input to be
true
by default, but for some reason, it refuses to get set to true. this is my code + a screenshot of what the result is in sanity studio:

{
      title: 'Show Product Reviews',
      name: 'showProductReviews',
      type: 'boolean',
      group: 'shopModule',
      initialValue: true
}
was wondering if anyone had any idea on what's going on or where i went wrong?
AI Update

I can totally see why this is confusing! The good news is your schema looks correct. The issue is likely that you're looking at an existing document that was created before you added the initialValue: true to your schema.

Here's what's happening: initialValue only applies when a new document is created. It doesn't retroactively update documents that already exist in your dataset. So if you had already created this document before adding initialValue: true to your schema, the field would still be false (or undefined, which displays as unchecked).

How to Fix This

Option 1: Create a New Document (quickest way to verify) Delete the existing document (or just create a new one) and you should see the toggle is checked by default.

Option 2: Update Existing Documents If you need existing documents to have this field set to true, you'll need to update them. You can do this in a few ways:

import {getCliClient} from 'sanity/cli'

const client = getCliClient()

// Fetch all documents of your type that need updating
const documents = await client.fetch(`*[_type == "yourDocumentType" && !defined(showProductReviews)]`)

// Update them
const transaction = client.transaction()
documents.forEach(doc => {
  transaction.patch(doc._id, {set: {showProductReviews: true}})
})

await transaction.commit()

Verify Your Schema Works

To confirm your initialValue is working correctly:

According to the Initial Value Templates documentation, field-level initialValue settings like yours apply to all new documents of that type when created through the Studio. Your syntax is spot-on:

{
  title: 'Show Product Reviews',
  name: 'showProductReviews',
  type: 'boolean',
  group: 'shopModule',
  initialValue: true  // âś… This is correct
}

The key takeaway: initialValue is about initialization, not migration. It sets the default for new documents, but doesn't change existing ones. This is actually a good thing - you wouldn't want your schema changes to unexpectedly modify existing content!

Show original thread
2 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