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)?
I'm wondering this too
For documents you can use initial value templates (https://www.sanity.io/docs/initial-value-templates ). For objects you can't
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
).

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.

Was this answer helpful?