Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

Is there a way to set the default state of a boolean to (false)?

3 replies
Last updated: Nov 12, 2020

Is there a way to set the default state of a boolean to (false)?

Nov 11, 2020, 5:56 PM

I'm wondering this too

Nov 11, 2020, 9:06 PM

For documents you can use initial value templates (https://www.sanity.io/docs/initial-value-templates ). For objects you can't

Nov 12, 2020, 6:18 AM

https://www.sanity.io/docs/boolean-type

Make sure your front-end code treats a missing boolean value as false.
In GROQ you can handle missing booleans and false values equally like this 
*[_type == 'story' && featured != true]
 which would match stories where featured is false or missing (or to be fair, any other value that is not
true
).

Nov 12, 2020, 6:19 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.