Skip to content

CheckboxList

Several values of a fixed list, optionally in groups. The value is a list of the chosen option values.

use Anvil\Schema\Fields\CheckboxList;
CheckboxList::make('channels')->options(['mail' => 'E-mail', 'sms' => 'SMS', 'push' => 'Push'])->columns(3),
CheckboxList::make('permissions')
->groupedOptions([
'Projects' => ['projects.view' => 'View', 'projects.edit' => 'Edit'],
'Reports' => ['reports.view' => 'View', 'reports.export' => 'Export'],
])
->columns(2)
->virtual(),
Option Effect Default
options([value => label]) the choices without groups
groupedOptions([group => [value => label]]) the choices under group headings
columns(n) checkboxes per row, 1 to 4 (one column on phones) 2

Plus the options of every field. Option values must not contain commas (InvalidArgumentException).

A list of the chosen values (strings) in the order of the options, without duplicates and without values that are not options. Nothing chosen is an empty list – the form always submits the field, so unchecking everything is saved.

A list is usually stored in another table, so the field is mostly virtual(): the resource saves it in afterSave() and fills it in formValues(), see Virtual fields. For a list in one column use a JSON column and encode it in afterSave(), or use a TagsInput for free values.

is_array for the field and in_list[…] of the option values for every item (permissions.*). required() needs at least one checked box.

Only the checked options, each with a check mark; “—” when none is checked. Groups keep their headings.

An array of strings with enum and uniqueItems. Integers are accepted and converted to strings.