Boolean builder rendered as a toggle switch. Prefer it for settings, preferences, and feature flags.
- Same API as
field.checkbox()- only the visual renderer changes - Use
defaultValue(true)when the toggle should start enabled - Keep
field.checkbox()for agreements and legal acceptance flows
Switch.web.tsxtsx
| 1 | const schema = { |
| 2 | notifications: field.switch('Enable email notifications'), |
| 3 | } |
Defaults, inheritance & field methods
- defaultValue is
false - type is
switch - Shared methods: see Base field builder
Switch-specific methods:
| Method | Type | Description |
|---|---|---|
mustBeTrue(message?) | message?: string | Blocks submit unless the switch is enabled. |
Recipes
Patterns that showcase switch-specific use cases.
Notifications on by default
Notifications.tsxtsx
| 1 | const schema = { |
| 2 | emailNotifications: field.switch('Enable email notifications') |
| 3 | .defaultValue(true), |
| 4 | } |
Profile visibility toggle
ProfileVisibility.tsxtsx
| 1 | const schema = { |
| 2 | publicProfile: field.switch('Public profile') |
| 3 | .hint('Visible to other members'), |
| 4 | } |
Mandatory billing activation
Billing.tsxtsx
| 1 | const schema = { |
| 2 | billing: field.switch('Enable billing') |
| 3 | .mustBeTrue('Billing must stay enabled for this plan.'), |
| 4 | } |