Closed
Description
Just upgraded to Symfony 2.7 from 2.5 and noticed that choice field attributes are getting applied to each options in PHP form templates. When I remove the call to the attributes block in the following line, the option attributes are not generated.
For example,
$builder->add(
'source',
'choice',
[
'choices' => $choices,
'expanded' => false,
'multiple' => false,
'label' => 'do_something,
'label_attr' => ['class' => 'control-label'],
'empty_value' => false,
'required' => false,
'attr' => [
'class' => 'form-control',
'onchange' => 'doSomething();'
]
]
);
Will result in something like
<select class='form-control' onchange='doSomething();'>
<option class='form-control' onchange='doSomething();' value=''>Foo</option>
<option class='form-control' onchange='doSomething();' value=''>Bar</option>
</select>
Is this intentional and if so, is there a recommended way to not do this (even if I set choice_attr => []
, it seems to be populating the option attributes with the select's attributes). Or is this a bug?