Select
API reference › HTML › Form › Select
Renders the HTML <select> element for choosing one or more options.
See also: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/select (BaseBlock for the base implementation.).
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attributes protected | mixed[] | HTML attributes array used by the implementing class. Default: []. | UIAwesome\ |
$content protected | string | Content string assigned to the element. Default: ''. | UIAwesome\ |
Methods
Section titled “Methods”Method details
Section titled “Method details”autocomplete()
Section titled “autocomplete() ”public function autocomplete(string|Stringable|UnitEnum|null $value): staticSets the autocomplete attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Autocomplete value, or null to remove the attribute. |
Returns
static: New instance with the updated autocomplete attribute.
form()
Section titled “form() ”public function form(string|Stringable|UnitEnum|null $value): staticSets the form attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Form ID, or null to remove the attribute. |
Returns
static: New instance with the updated form attribute.
getContent()
Section titled “getContent() ”public function getContent(): stringReturns the content with every appended option and option group rendered in place.
Children are rendered on access, so the value configured through value() is applied to the current
option instances.
Returns
string: Content with the appended children rendered in place.
multiple()
Section titled “multiple() ”public function multiple(bool|null $value): staticSets the multiple attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | bool| | Multiple state. Use true to allow multiple values, false to disallow, or null to remove the attribute. |
Returns
static: New instance with the updated multiple attribute.
optgroup()
Section titled “optgroup() ”public function optgroup(UIAwesome\Html\Form\Optgroup $optgroup): staticAppends an <optgroup> element to the select.
Parameters
| Parameter | Type | Description |
|---|---|---|
$optgroup | Optgroup | Optgroup element instance. |
Returns
static: New instance with the appended optgroup.
option()
Section titled “option() ”public function option(UIAwesome\Html\Form\Option $option): staticAppends an <option> element to the select.
Parameters
| Parameter | Type | Description |
|---|---|---|
$option | Option | Option element instance. |
Returns
static: New instance with the appended option.
options()
Section titled “options() ”public function options(UIAwesome\Html\Form\Option ...$options): staticAppends multiple <option> elements to the select.
Parameters
| Parameter | Type | Description |
|---|---|---|
...$options | Option | Option element instances. |
Returns
static: New instance with the appended options.
required()
Section titled “required() ”public function required(bool|null $value): staticSets the required attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | bool| | Required state. Use true to require a value, false to make it optional, or null to remove the attribute. |
Returns
static: New instance with the updated required attribute.
value()
Section titled “value() ”public function value(mixed[]|bool|float|int|string|Stringable|UnitEnum|null $value): staticSets the value or values used to select child options.
The selected value is rendering state and is never serialized as a value attribute on the <select>.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed[]|Stringable|UnitEnum| | Selected value or values. Must be an array or null when multiple is true, and must not hold more than one value otherwise; the constraint is enforced on render. |
Returns
static: New instance with the updated selected value.
getTag()
Section titled “getTag() ”protected function getTag(): UIAwesome\Html\Interop\BlockReturns the tag enumeration for the <select> element.
run()
Section titled “run() ”protected function run(): stringValidates the selected value and renders the <select> element.
Returns
string: Rendered HTML for the <select> element.
Throws
InvalidArgumentException: if the selected value does not match themultipleattribute.