Skip to content

ChoiceType generates options in selectbox with parent's attributes #16534

Closed
@ossinkine

Description

@ossinkine

I've created TestFormType

class TestType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('choice', 'choice', ['choices' => ['foo', 'bar']]);
    }

    public function getName()
    {
        return 'test';
    }
}

created the form in the controller and passed to the view

class DefaultController extends Controller
{
    public function indexAction(Request $request)
    {
        return $this->render('AppBundle::index.html.php', [
            'form' => $this->createForm('test')->createView(),
        ]);
    }
}

rendered in the view

<?php echo $view['form']->widget($form['choice']) ?>

and I got this:

<select id="test_choice" name="test[choice]">
    <option value="0" id="test_choice" name="test[choice]" required="required">foo</option>
    <option value="1" id="test_choice" name="test[choice]" required="required">bar</option>
</select>

Options have the same attributes as select. Options shoud not have them.

I'm working on the latest version of 2.7 branch

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions