Giter Club home page Giter Club logo

Comments (2)

Xerkus avatar Xerkus commented on July 29, 2024

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:

https://github.com/laminas/laminas-form/blob/c6100a664879b6f5638b0fae0c844051f2159902/test/View/Helper/FormSelectTest.php#L71C98-L71C98

from laminas-form.

froschdesign avatar froschdesign commented on July 29, 2024

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

from laminas-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.