Skip to content

Select

One value of a fixed list, as a drop-down.

use Anvil\Schema\Fields\Select;
Select::make('status')
->options(['draft' => 'Draft', 'sent' => 'Sent', 'paid' => 'Paid'])
->required()
->default('draft'),
Select::make('priority')->options([1 => 'Low', 2 => 'Normal', 3 => 'High'])->placeholder('Choose…'),
Option Effect
options([value => label]) the choices, in this order
placeholder('…') label of the empty first option (default “—”)

Plus the options of every field.

Option values must not contain commas (they end up in an in_list[…] rule); options() throws an InvalidArgumentException otherwise. Labels are escaped.

For a few options that should all be visible use a Radio; for several values a CheckboxList; for records of another table a BelongsTo.

The value of the chosen option, null when nothing is chosen.

in_list[…] of the option values: a manipulated request cannot save a value that is not offered. Then the rules of rules().

The label of the stored value. A stored value that is no longer an option is shown as it is.

A string with enum of the option values.