Checkbox Group
Displays a group of checkboxes.
Requires JS
This component requires the checkbox
stimulus controller.
API Reference
CheckboxGroup
Name | Type | Default |
---|---|---|
required name: | string | |
Base name for the checkbox group. If name: "fruits" , individual checkboxes will have name="fruits[]" , allowing multiple values to be submitted as an array. | ||
value: | array | [] |
Array of currently selected values. Checkboxes with values in this array will be checked. | ||
include_hidden: | boolean | true |
Whether to include a hidden field that ensures the parameter is sent even when no checkboxes are selected. | ||
attributes | keyword arguments |
CheckboxGroup#items (Builder)
Builder method that generates multiple checkboxes from a collection automatically.
Name | Type | Default |
---|---|---|
required collection | array | |
Array of objects or hashes to convert into checkboxes. Each item will generate one checkbox. | ||
required value_method: | symbol | |
Method called on each collection item to get the checkbox value (what's submitted when checked). | ||
required text_method: | symbol | |
Method called on each collection item to get the display text for the checkbox label. | ||
container_class: | string | nil |
CSS class applied to the container <div> wrapping each checkbox and its label. | ||
disabled_items: | string or array | nil |
Value(s) of checkboxes that should be disabled and non-interactive. | ||
id_prefix: | string | nil |
Custom prefix for individual checkbox IDs. If not provided, uses the name parameter as the prefix. |
CheckboxGroup#label (Builder)
Builder method to set default attributes for all checkbox labels in the group.
Name | Type | Default |
---|---|---|
attributes | keyword arguments | |
HTML attributes that will be applied to every label element generated by the items method. |
CheckboxGroup#checkbox (Builder)
Builder method to set default attributes for all checkboxes in the group.
Name | Type | Default |
---|---|---|
attributes | keyword arguments | |
HTML attributes that will be applied to every checkbox element generated by the items method. |
Examples
On This Page