Studio

Boolean

Schema type reference for expressing truthy values.

A boolean, true or false. See the BooleanDefinition reference for the full type definition.

Loading...
A boolean field with title and description

Properties

  • Requiredtype

    Value must be set to boolean.

  • Requiredname

    The field name. This becomes the key in the document.

  • Human-readable label for the field.

  • If set to true, this field is hidden in the studio. You can also supply a callback function to make it a conditional field.

  • If set to true, this field is not editable in the studio. You can also supply a callback function to make it a conditional field.

  • Short description for editors of how the field is to be used.

  • The initial value used when creating new values of this type. Can be a literal value, or a resolver function that returns a literal value or a promise that resolves to one.

  • Lets you provide custom components to override the studio defaults in various contexts. The available keys are diff, field, input, item, and preview.

  • Marks a field or document type as deprecated in the studio interface and displays a user-defined message set through the single required reason property.

    If you deploy a GraphQL API schema, this property is translated into the @deprecated directive.

  • Supply a custom icon for this field. See the icons documentation for more information.

Options

These options apply to boolean fields. See the BooleanOptions reference for the full type definition.

  • Either switch or checkbox. Defaults to switch.

    Controls the visual appearance of the input. A switch reads as an on/off state; a checkbox reads as an item you tick.

  • Configures how Sanity Create interfaces with this field. Set exclude: true to leave the field out of Sanity Create, or purpose to describe what the field holds so that content mapping can use it.

  • Configures how Canvas interfaces with this field. Takes the same exclude and purpose properties as sanityCreate.

Validation

Chain these methods on the rule passed to validation. See the BooleanRule reference for the full type definition.

  • Ensures that this field exists.

  • Discards the validation rules set before it in the chain and makes the field optional. Rules chained after it still apply.

  • Creates a custom validation rule.

  • Sets a custom error message for the preceding validation rule.

  • Sets a custom warning message for the preceding validation rule. Warnings do not prevent publishing.

  • Sets a custom info message for the preceding validation rule. Info messages are purely informational and do not prevent publishing.

  • Gets the value of a sibling field to use in validation. Useful for creating validation rules that depend on the value of another field.

Input

Response

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

New documents are created without schema-defined fields. A boolean field in your schema does not immediately produce documents containing that key: the key must be assigned a value before it appears in a document. Make sure your frontend code treats a missing boolean value as false.

Pro tip

Was this page helpful?