Skip to content
PHP Ecosystem
Explore

Select

API reference › HTML › Form › Select

final classUIAwesome\Html\Form\Select
ExtendsUIAwesome\Html\Core\Element\BaseBlock » UIAwesome\Html\Core\Base\BaseTag
ImplementsUIAwesome\Html\Contracts\Form\FormControlInterface, UIAwesome\Html\Contracts\Form\MultiValueInterface, UIAwesome\Html\Contracts\Attribute\ValueInterface, UIAwesome\Html\Contracts\Attribute\AttributesInterface, UIAwesome\Html\Contracts\Element\BlockInterface, UIAwesome\Html\Contracts\Element\ClearableContentInterface, UIAwesome\Html\Contracts\RenderableInterface
Uses traitsUIAwesome\Html\Attribute\CanBeDisabled, UIAwesome\Html\Attribute\HasName, UIAwesome\Html\Form\Mixin\HasSelectableChildren, UIAwesome\Html\Form\Mixin\HasSize, UIAwesome\Html\Attribute\Global\CanBeAutofocus, UIAwesome\Html\Attribute\Global\CanBeHidden, UIAwesome\Html\Attribute\Global\HasAccesskey, UIAwesome\Html\Attribute\Global\HasAria, UIAwesome\Html\Mixin\HasAttributes, UIAwesome\Html\Attribute\Global\HasClass, UIAwesome\Html\Mixin\HasContent, UIAwesome\Html\Attribute\Global\HasContentEditable, UIAwesome\Html\Attribute\Global\HasData, UIAwesome\Html\Attribute\Global\HasDir, UIAwesome\Html\Attribute\Global\HasDraggable, UIAwesome\Html\Attribute\Global\HasEvents, UIAwesome\Html\Attribute\Global\HasId, UIAwesome\Html\Attribute\Global\HasLang, UIAwesome\Html\Attribute\Global\HasMicroData, UIAwesome\Html\Attribute\Global\HasRole, UIAwesome\Html\Attribute\Global\HasSpellcheck, UIAwesome\Html\Attribute\Global\HasStyle, UIAwesome\Html\Attribute\Global\HasTabindex, UIAwesome\Html\Attribute\Global\HasTitle, UIAwesome\Html\Attribute\Global\HasTranslate, UIAwesome\Html\Core\Event\HasAfterRun, UIAwesome\Html\Core\Event\HasBeforeRun
Sourcesrc/Form/Select.php

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.).

PropertyTypeDescriptionDefined by
$attributes protectedmixed[]HTML attributes array used by the implementing class. Default: [].UIAwesome\Html\Mixin\HasAttributes
$content protectedstringContent string assigned to the element. Default: ''.UIAwesome\Html\Mixin\HasContent
MethodDescriptionDefined by
__construct() finalInitializes a new tag instance.UIAwesome\Html\Core\Base\BaseTag
__toString()Returns the rendered tag string.UIAwesome\Html\Core\Base\BaseTag
accesskey()Sets the accesskey attribute.UIAwesome\Html\Attribute\Global\HasAccesskey
addAriaAttribute()Sets an aria-* attribute.UIAwesome\Html\Attribute\Global\HasAria
addAttribute()Adds or updates a single HTML attribute for the element.UIAwesome\Html\Mixin\HasAttributes
addDataAttribute()Sets a data-* attribute.UIAwesome\Html\Attribute\Global\HasData
addEvent()Sets an on* event attribute.UIAwesome\Html\Attribute\Global\HasEvents
ariaAttributes()Sets multiple aria-* attributes.UIAwesome\Html\Attribute\Global\HasAria
attributes()Adds or updates multiple HTML attributes for the element.UIAwesome\Html\Mixin\HasAttributes
autocomplete()Sets the autocomplete attribute.Select
autofocus()Sets the autofocus attribute.UIAwesome\Html\Attribute\Global\CanBeAutofocus
begin() finalStarts begin/end rendering for this instance.UIAwesome\Html\Core\Element\BaseBlock
class()Sets the class attribute.UIAwesome\Html\Attribute\Global\HasClass
clearContent()Clears encoded and raw content without changing other component state.UIAwesome\Html\Mixin\HasContent
config()Applies application-scoped config recipes to this tag.UIAwesome\Html\Core\Base\BaseTag
content()Appends encoded content.UIAwesome\Html\Mixin\HasContent
contentEditable()Sets the contenteditable attribute.UIAwesome\Html\Attribute\Global\HasContentEditable
dataAttributes()Sets multiple data-* attributes.UIAwesome\Html\Attribute\Global\HasData
dir()Sets the dir attribute.UIAwesome\Html\Attribute\Global\HasDir
disabled()Sets the disabled attribute.UIAwesome\Html\Attribute\CanBeDisabled
draggable()Sets the draggable attribute.UIAwesome\Html\Attribute\Global\HasDraggable
end() static finalEnds the most recent begin/end rendering block for the current class.UIAwesome\Html\Core\Element\BaseBlock
events()Sets multiple on* event attributes.UIAwesome\Html\Attribute\Global\HasEvents
form()Sets the form attribute.Select
getAttribute()Returns the value of a single HTML attribute.UIAwesome\Html\Mixin\HasAttributes
getAttributes()Returns the array of HTML attributes for the element.UIAwesome\Html\Mixin\HasAttributes
getContent()Returns the content with every appended option and option group rendered in place.Select
hidden()Sets the hidden attribute.UIAwesome\Html\Attribute\Global\CanBeHidden
html()Appends trusted raw HTML content without encoding or sanitizing it.UIAwesome\Html\Mixin\HasContent
id()Sets the id attribute.UIAwesome\Html\Attribute\Global\HasId
itemId()Sets the itemid attribute.UIAwesome\Html\Attribute\Global\HasMicroData
itemProp()Sets the itemprop attribute.UIAwesome\Html\Attribute\Global\HasMicroData
itemRef()Sets the itemref attribute.UIAwesome\Html\Attribute\Global\HasMicroData
itemScope()Sets the itemscope attribute.UIAwesome\Html\Attribute\Global\HasMicroData
itemType()Sets the itemtype attribute.UIAwesome\Html\Attribute\Global\HasMicroData
lang()Sets the lang attribute.UIAwesome\Html\Attribute\Global\HasLang
multiple()Sets the multiple attribute.Select
name()Sets the name attribute.UIAwesome\Html\Attribute\HasName
optgroup()Appends an <optgroup> element to the select.Select
option()Appends an <option> element to the select.Select
options()Appends multiple <option> elements to the select.Select
removeAriaAttribute()Removes an aria-* attribute.UIAwesome\Html\Attribute\Global\HasAria
removeAttribute()Removes a specific HTML attribute from the element.UIAwesome\Html\Mixin\HasAttributes
removeDataAttribute()Removes a data-* attribute.UIAwesome\Html\Attribute\Global\HasData
removeEvent()Removes an on* event attribute.UIAwesome\Html\Attribute\Global\HasEvents
render() finalRenders the tag with lifecycle hooks.UIAwesome\Html\Core\Base\BaseTag
replaceAttributes()Replaces all HTML attributes for the element.UIAwesome\Html\Mixin\HasAttributes
required()Sets the required attribute.Select
role()Sets the role attribute.UIAwesome\Html\Attribute\Global\HasRole
size()Sets the size attribute.UIAwesome\Html\Form\Mixin\HasSize
spellcheck()Sets the spellcheck attribute.UIAwesome\Html\Attribute\Global\HasSpellcheck
style()Sets the style attribute.UIAwesome\Html\Attribute\Global\HasStyle
tabIndex()Sets the tabindex attribute.UIAwesome\Html\Attribute\Global\HasTabindex
tag() staticCreates and configures a new tag instance.UIAwesome\Html\Core\Base\BaseTag
title()Sets the title attribute.UIAwesome\Html\Attribute\Global\HasTitle
translate()Sets the translate attribute.UIAwesome\Html\Attribute\Global\HasTranslate
value()Sets the value or values used to select child options.Select
afterRun() protectedPost-processes rendered output.UIAwesome\Html\Core\Event\HasAfterRun
beforeRun() protectedValidates state before rendering.UIAwesome\Html\Core\Event\HasBeforeRun
getTag() protectedReturns the tag enumeration for the <select> element.Select
isBeginExecuted() protectedIndicates whether this instance has an open or closing operation in the current context.UIAwesome\Html\Core\Element\BaseBlock
loadDefault() protectedReturns class-level default definitions.UIAwesome\Html\Core\Base\BaseTag
run() protectedValidates the selected value and renders the <select> element.Select
runBegin() protectedReturns the opening tag for begin/end rendering.UIAwesome\Html\Core\Element\BaseBlock
public function autocomplete(string|Stringable|UnitEnum|null $value): static

Sets the autocomplete attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullAutocomplete value, or null to remove the attribute.

Returns

static: New instance with the updated autocomplete attribute.

public function form(string|Stringable|UnitEnum|null $value): static

Sets the form attribute.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullForm ID, or null to remove the attribute.

Returns

static: New instance with the updated form attribute.

public function getContent(): string

Returns 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.

public function multiple(bool|null $value): static

Sets the multiple attribute.

Parameters

ParameterTypeDescription
$valuebool|nullMultiple 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.

public function optgroup(UIAwesome\Html\Form\Optgroup $optgroup): static

Appends an <optgroup> element to the select.

Parameters

ParameterTypeDescription
$optgroupOptgroupOptgroup element instance.

Returns

static: New instance with the appended optgroup.

public function option(UIAwesome\Html\Form\Option $option): static

Appends an <option> element to the select.

Parameters

ParameterTypeDescription
$optionOptionOption element instance.

Returns

static: New instance with the appended option.

public function options(UIAwesome\Html\Form\Option ...$options): static

Appends multiple <option> elements to the select.

Parameters

ParameterTypeDescription
...$optionsOptionOption element instances.

Returns

static: New instance with the appended options.

public function required(bool|null $value): static

Sets the required attribute.

Parameters

ParameterTypeDescription
$valuebool|nullRequired 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.

public function value(mixed[]|bool|float|int|string|Stringable|UnitEnum|null $value): static

Sets 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

ParameterTypeDescription
$valuemixed[]|bool|float|int|string|Stringable|UnitEnum|nullSelected 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.

protected function getTag(): UIAwesome\Html\Interop\Block

Returns the tag enumeration for the <select> element.

Returns

Block: Tag enumeration instance for <select>. Block for valid block-level tags.

protected function run(): string

Validates the selected value and renders the <select> element.

Returns

string: Rendered HTML for the <select> element.

Throws