> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/database/schema/field-types/boolean.md).

# Boolean

A yes / no field stored as true or false and shown as a checkbox.

A **Yes / No** field stores `true` or `false`. The record form shows it as a checkbox.

**Builder:** Form fields panel → **Yes/No** · widget `boolean` · data type `boolean.schema.v1`

## Data schema

```json
{
  "inStock": {
    "type": "boolean",
    "default": true
  }
}
```

| Keyword   | Required | What it does                                                                     | Example     |
| --------- | -------- | -------------------------------------------------------------------------------- | ----------- |
| `type`    | yes      | Always `"boolean"`.                                                              | `"boolean"` |
| `default` | no       | Whether the box starts ticked and what a record gets when the field is left out. | `true`      |

### What the server refuses

Every write — insert, update, replace; from Cloud, the API, an SDK, the CLI or an AI agent — is checked against the published schema. A broken value is answered with one error per field: the code, and `Field '<name>' is invalid: <reason>`. Nothing is written.

| Case                                  | Code                     | The reason it gives   |
| ------------------------------------- | ------------------------ | --------------------- |
| a required field is missing or `null` | `CM-ERRORS-DATABASE-030` | `a value is required` |
| not a boolean (`"yes"`, `1`, …)       | `CM-ERRORS-DATABASE-039` | `must be a boolean`   |

A keyword that is not in the table above is refused when the schema is **saved**, not when a record is written: `CM-ERRORS-SCHEMA-010` — `Data schema violates meta-schema: Property 'sort' has not been defined and the schema does not allow additional properties. Path 'properties.inStock.sort' (field 'properties.inStock' checked as boolean.schema.v1).`

## UI schema

The cell uses the `boolean` widget; `help` is shown next to the box.

```json
{
  "colSpan": 6,
  "element": {
    "fieldId": "inStock",
    "meta": { "widget": "boolean", "label": "In stock", "help": "Untick when the last copy is sold" }
  }
}
```

Every cell also takes the common layout options: `label`, `placeholder`, `help` (the text under the input), `required`, `readonly` and `hidden`. Keys outside this list — `watermark`, `hint`, `permissions` — are refused when the schema is saved (`CM-ERRORS-SCHEMA-012`), see [Schema authoring guide](/codemash/cloud/database/schema.md#one-contract-no-second-dialect).

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-bcf26f7d9372841fb5f83e4ed37825abe1941052%2Ffield-types-dates-1.png?alt=media" alt="The Dates, flags &#x26; places tab of the all-types record form with the checkboxes Boolean plain (with a help text), Boolean type and Boolean default"><figcaption><p>Boolean cells are checkboxes.</p></figcaption></figure>

## Records

A record the schema accepts:

```json
{ "inStock": true }
```

A record it refuses:

```json
{ "inStock": "yes" }
```

The answer: `CM-ERRORS-DATABASE-039` — `Field 'inStock' is invalid: must be a boolean`. In Cloud the same sentence is shown under the field before the form is sent; the server repeats the check on every API write.

## Good to know

* A required boolean must be present (`true` or `false`); `null` is refused with `a value is required`.

## Do it from code

```ts
await norbix.api.database.insertOne({
  collectionName: 'books',
  document: JSON.stringify({ inStock: true }),
});
```

```sh
norbix api database one insert --collectionName books --document '{"inStock":true}'
```

The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Insert One](/codemash/api-reference/database/collections/insert-one.md) · [Save Database Schema](/codemash/api-reference/database/schemas/save-database-schema.md)

## Related

[Enum](/codemash/cloud/database/schema/field-types/enum.md) · [Field type reference](/codemash/cloud/database/schema/field-types.md) · [Schema authoring guide](/codemash/cloud/database/schema.md) · [Create a schema](/codemash/cloud/database/collections/create-schema.md)
