👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

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– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?