Question

How can I add a class to a select drop down list.

Below is my attempt to do it. I have tried to do it with the attributes but this doesn't appear to work with select tag.

 $this->add(
            array(
                'type' => 'DoctrineModule\Form\Element\ObjectSelect',
                'name' => 'jobId',
                'options' => array(
                    'object_manager' => $this->getObjectManager(),
                    'target_class'   => 'FormDependencies\Entity\JobList',
                    'property'       => 'job',
                    'empty_option'   => '--- please choose ---',
                     'attributes' => array(
                      'class'  => 'testing',
                       )
                ),
              )
           ); 

Thank you in advance for your help.

below is the rendered input bar: you will see that the class has not been added;

<select name="Jobs[jobId]">
Was it helpful?

Solution

The attributes array should not be nested within options; but rather on the same level.

$this->add(array(
    'name' => 'jobId',
    'type' => 'DoctrineModule\Form\Element\ObjectSelect',
    'options' => array(
        'foo' => 'bar'
    ),
    'attributes' => array(
        'class'  => 'testing',
    ),
));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top