Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ossinkine opened this issue Nov 12, 2015 · 6 comments
Closed

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

ossinkine opened this issue Nov 12, 2015 · 6 comments

Comments

@ossinkine
Copy link
Contributor

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

@xabbuh xabbuh added the Form label Nov 12, 2015
@xabbuh
Copy link
Member

xabbuh commented Nov 12, 2015

@ossinkine Can you provide a fork of the Symfony Standard Edition that reproduces your issue?

@ossinkine
Copy link
Contributor Author

@ossinkine
Copy link
Contributor Author

@webmozart You have added rendering parent's attributes (03efce1#diff-b56b980552f37a32080a57032805f34dR11). Could you please explain for what did you do this and how should it work?

@xabbuh
Copy link
Member

xabbuh commented Jun 21, 2017

This seems to have been fixed in the meantime. I could reproduce your issue with the Symfony version locked in your example project (i.e. 2.7.6), but it was resolved updating to Symfony 2.7.29 (which is the latest patch release for Symfony 2.7).

@xabbuh xabbuh closed this as completed Jun 21, 2017
@xabbuh
Copy link
Member

xabbuh commented Jun 21, 2017

probably solved by #19020 which fixed #19016

@ossinkine
Copy link
Contributor Author

I confirm, fixed in 2.7.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants