Boolean

A boolean, true or false.

Properties

  • REQUIREDtypestring

    Value must be set to boolean.

Options

  • layoutstring

    Either switch (default) or checkbox

    This let's you control the visual appearance of the input. By default the input for boolean fields will display as a switch, but you can also make it appear as a checkbox

Validation

  • required()function

    Ensures that this field exists.

  • custom(fn)function

    Creates a custom validation rule.

Input

{
  title: 'Has the movie been released?',
  name: 'released',
  type: 'boolean'
}

Output

{
  "_type": "movie",
  "released": true,
  ...
}

New documents are created without schema-defined fields. This means that a boolean field in your schema will not immediately result in documents containing the boolean key. The key must be assigned a value for it to appear in a document. Make sure your front-end code treats a missing boolean value as false.

Protip

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).