Closed mattfletcher closed 1 year ago
class
is an attribute, not an option:
$valueOptions = [];
foreach (countries() as $country) {
$valueOptions[] = [
'name' => $country['name'],
'attributes' => [
'class' => 'fi fi-' . strtolower($country['iso_3166_1_alpha2']),
],
'value' => $country['iso_3166_1_alpha2'],
'label' => $country['name'] . ' (+' . $country['calling_code'] . ')',
];
}
usort($valueOptions, static fn($a, $b) => $a['name'] <=> $b['name']);
$element = new Select(self::COUNTRY_CALLING_CODE);
$element->setLabel('Country calling code');
$element->setValueOptions($valueOptions);
There is a test asserting class attribute is utilized, so marking this as not a bug:
This can also be found in the documentation:
Attributes on the options are supported by providing the options as a specification array instead of key-value pairs:
https://docs.laminas.dev/laminas-form/v3/element/select/#basic-usage
Bug Report
Summary
It is not possible to set a class="" attribute on a
Current behavior
The class attributes specified on the valueOptions array are stripped out.
How to reproduce
Expected behavior
Each option would have a class attribute of "fi fi-gb" (etc)