문제

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]">
도움이 되었습니까?

해결책

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',
    ),
));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top