Checkbox Group

Displays a group of checkboxes.

API Reference

CheckboxGroup

NameTypeDefault
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:booleantrue
Whether to include a hidden field that ensures the parameter is sent even when no checkboxes are selected.
attributeskeyword arguments

CheckboxGroup#items (Builder)

Builder method that generates multiple checkboxes from a collection automatically.

NameTypeDefault
required collectionarray
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:stringnil
CSS class applied to the container <div> wrapping each checkbox and its label.
disabled_items:string or arraynil
Value(s) of checkboxes that should be disabled and non-interactive.
id_prefix:stringnil
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.

NameTypeDefault
attributeskeyword 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.

NameTypeDefault
attributeskeyword arguments
HTML attributes that will be applied to every checkbox element generated by the items method.

Examples