Checkbox & Toggle
Single checkbox or toggle switch for boolean yes/no choices.
Checkbox and toggle fields represent a single true/false choice. Use checkboxes for agreements and opt-ins, toggles for settings and feature switches.
Field Types
Basic Usage
Add checkbox or toggle fields using the addCheckbox() or addToggle() builder methods:
Available Settings
Checkboxes and toggles are simple boolean fields. The main configuration option is whether they are required.
Toggle Switches
Toggles give better visual feedback for on/off states, making them a good fit for settings:
Validation
Checkbox and toggle fields are validated by the TextFieldValidator. When required, the field must be checked/enabled:
Submitted Data Format
Checkbox and toggle fields submit boolean values:
{
"agree_to_terms": true,
"subscribe_newsletter": false,
"notifications_enabled": true
} Unchecked checkboxes and disabled toggles submit false. Checked/enabled fields submit true.
Frontend Behavior
- Click or tap to toggle the state
- Space bar toggles when focused via keyboard
- Checkboxes show a checkmark when checked
- Toggles slide and change color when enabled
- Labels are clickable to toggle the field
- Shows validation errors inline
When to Use
Use Checkbox For:
- Terms and conditions acceptance
- Newsletter opt-ins
- Agreement to policies
- Explicit consent
- One-time actions
Use Toggle For:
- Settings and preferences
- Feature enables/disables
- Notification controls
- Visibility toggles
- Ongoing state changes
Accessibility
Both checkboxes and toggles include ARIA attributes, keyboard navigation and focus indicators. Labels are associated with inputs for screen reader support and the current state is announced when changed via keyboard.