react-formbridge
Browse documentation
Field buildersv1.0.2

field.switch()

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
1const schema = {
2 notifications: field.switch('Enable email notifications'),
3}

Defaults, inheritance & field methods

Switch-specific methods:

MethodTypeDescription
mustBeTrue(message?)message?: stringBlocks submit unless the switch is enabled.

Recipes

Patterns that showcase switch-specific use cases.

Notifications on by default

Notifications.tsxtsx
1const schema = {
2 emailNotifications: field.switch('Enable email notifications')
3 .defaultValue(true),
4}

Profile visibility toggle

ProfileVisibility.tsxtsx
1const schema = {
2 publicProfile: field.switch('Public profile')
3 .hint('Visible to other members'),
4}

Mandatory billing activation

Billing.tsxtsx
1const schema = {
2 billing: field.switch('Enable billing')
3 .mustBeTrue('Billing must stay enabled for this plan.'),
4}