Skip to content
PHP Ecosystem
Explore

ChoiceItem

API reference › HTML › Form › ChoiceItem

final classUIAwesome\Html\Form\ChoiceItem
Sourcesrc/Form/ChoiceItem.php

Defines one value and label rendered by a checkbox or radio list.

The item carries no name, id, or checked state: AbstractChoiceList derives them from the list and passes them in on render.

CheckboxList and RadioList for the lists rendering the items.

MethodDescriptionDefined by
label()Sets the item label.ChoiceItem
labelAttributes()Sets attributes applied to the item label.ChoiceItem
labelClass()Adds a CSS class to the item label.ChoiceItem
tag() staticCreates a choice item.ChoiceItem
value()Sets the submitted item value.ChoiceItem
public function label(string|Stringable $value): self

Sets the item label.

Parameters

ParameterTypeDescription
$valuestring|StringableLabel text, encoded on render.

Returns

self: New instance with the updated label.

public function labelAttributes(mixed[] $values): self

Sets attributes applied to the item label.

Merges with the attributes already configured, so consecutive calls accumulate.

Parameters

ParameterTypeDescription
$valuesmixed[]Label attributes indexed by attribute name.

Returns

self: New instance with the updated label attributes.

public function labelClass(string|Stringable|UnitEnum|null $value, bool $override = false): self

Adds a CSS class to the item label.

Parameters

ParameterTypeDescription
$valuestring|Stringable|UnitEnum|nullClass name, or null to remove the attribute.
$overrideboolWhether to replace the existing classes instead of merging them.

Returns

self: New instance with the updated label class.

public static function tag(): self

Creates a choice item.

Returns

self: New item instance.

public function value(bool|float|int|string|Stringable|UnitEnum|null $value): self

Sets the submitted item value.

Parameters

ParameterTypeDescription
$valuebool|float|int|string|Stringable|UnitEnum|nullSubmitted value, or null to remove the attribute.

Returns

self: New instance with the updated value.