---
title: "toggle"
image: "https://adonia.pages.dev/og.png"
version: "next"
---

> Documentation Index
> Fetch the complete documentation index at: https://adonia.pages.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# toggle

<!-- Generated by `pnpm docs:fields` from packages/core/src/schema/fields/toggle.ts. Edit the TSDoc, not this file. -->

Switch bound to a boolean attribute — the "state now" affordance, where
`checkbox` is the "opt in" one.

| | |
| --- | --- |
| Builder | `F.toggle(attribute: string): Toggle` |
| Wire type key | `toggle` |
| Class chain | `Toggle` → `BooleanField` → `Field` |
| Detail projection | `text-entry` |
| Column counterpart | `boolean` cell, i.e. `C.boolean(attribute)` |

## Example

```ts
import { F } from '@adonia/core'

F.toggle('isPublished').label('Published').onLabel('Live').offLabel('Hidden')
```

## Props

Beyond the shared [field DSL](/reference/fields#the-shared-field-dsl):

| Prop | Declared on | Behaviour |
| --- | --- | --- |
| `onLabel(text: string): this` | `Toggle` | Caption shown beside the switch while it is on. |
| `offLabel(text: string): this` | `Toggle` | Caption shown beside the switch while it is off. |
| `onColor(token: string): this` | `Toggle` | Palette token for the switch's on state (`'green'`, `'amber'`, …). |
| `asInteger(): this` | `BooleanField` | Stores the sqlite-shaped `0`/`1` integer instead of a boolean (§7.3). Needed when the model does NOT declare a boolean column consumer; with it, `BooleanField.defaultDehydrate` writes `1`/`0`, which `BooleanField.defaultHydrate` reads straight back. |

## Validation

Vine base: `vine.boolean()`.

§11.1 mapping: `vine.boolean()`.

Contributed by `BooleanField.vineSchema()` in `packages/core/src/schema/fields/boolean_field.ts`. The shared modifiers (`required`, `nullable`, `requiredWhen`, `unique`, optionality) are applied on top by `Field.buildValidation`, and a `rules()` override replaces the base entirely — the validator compiler never branches on the field class.

## Declared in

- `packages/core/src/schema/fields/toggle.ts` — `Toggle`
- `packages/core/src/schema/fields/boolean_field.ts` — `BooleanField`

Source: https://adonia.pages.dev/reference/fields/toggle/index.mdx
