Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 1.22 KB

select.md

File metadata and controls

59 lines (46 loc) · 1.22 KB

Select Field

Represents <select> element that provides a menu of options. Documentation:

Usage Example

Form model:

final class ProfileForm extends FormModel
{
    public ?string $color = 'f00';

    public function getAttributeLabels(): array
    {
        return [
            'color' => 'Select color',
        ];
    }
}

Widget:

echo Select::widget()
    ->formAttribute($profileForm, 'color')
    ->optionsData([
        'f00' => 'Red',
        '0f0' => 'Green',
        '00f' => 'Blue',
    ]);

Result will be:

<div>
    <label for="profileform-color">Select color</label>
    <select id="profileform-color" name="ProfileForm[color]">
        <option value="f00">Red</option>
        <option value="0f0">Green</option>
        <option value="00f">Blue</option>
    </select>
</div>

Supported Values

  • string
  • number or numeric string (see is_numeric())
  • bool
  • null
  • any stringable values

Multiple select requires iterable or null value.