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…'),Options
Section titled “Options”| 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.
Options can depend on another field.
For a few options that should all be visible use a Radio; for several values a CheckboxList; for records of another table a BelongsTo.
Saved value
Section titled “Saved value”The value of the chosen option, null when nothing is chosen.
Validation
Section titled “Validation”in_list[…] of the option values: a manipulated request cannot save a
value that is not offered. Then the rules of rules().
Read-only
Section titled “Read-only”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.