ChoiceItem
API reference › HTML › Form › ChoiceItem
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.
Methods
Section titled “Methods”| Method | Description | Defined 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() static | Creates a choice item. | ChoiceItem |
value() | Sets the submitted item value. | ChoiceItem |
Method details
Section titled “Method details”label()
Section titled “label() ”public function label(string|Stringable $value): selfSets the item label.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable | Label text, encoded on render. |
Returns
self: New instance with the updated label.
labelAttributes()
Section titled “labelAttributes() ”public function labelAttributes(mixed[] $values): selfSets attributes applied to the item label.
Merges with the attributes already configured, so consecutive calls accumulate.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed[] | Label attributes indexed by attribute name. |
Returns
self: New instance with the updated label attributes.
labelClass()
Section titled “labelClass() ”public function labelClass(string|Stringable|UnitEnum|null $value, bool $override = false): selfAdds a CSS class to the item label.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Class name, or null to remove the attribute. |
$override | bool | Whether to replace the existing classes instead of merging them. |
Returns
self: New instance with the updated label class.
tag()
Section titled “tag() ”public static function tag(): selfCreates a choice item.
Returns
self: New item instance.
value()
Section titled “value() ”public function value(bool|float|int|string|Stringable|UnitEnum|null $value): selfSets the submitted item value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | bool|Stringable|UnitEnum| | Submitted value, or null to remove the attribute. |
Returns
self: New instance with the updated value.