8000 [Form] Choice attr is applied to each <option /> · Issue #19016 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Choice attr is applied to each <option /> #19016

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
alanhartless opened this issue Jun 10, 2016 · 2 comments
Closed

[Form] Choice attr is applied to each <option /> #19016

alanhartless opened this issue Jun 10, 2016 · 2 comments

Comments

@alanhartless
Copy link

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.

https://github.com/symfony/framework-bundle/blob/master/Resources/views/Form/choice_widget_options.html.php#L11

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?

@javiereguiluz javiereguiluz changed the title Choice attr is applied to each <option /> [Form] Choice attr is applied to each <option /> Jun 10, 2016
@HeahDude
Copy link
Contributor

Looks like a bug to me.

@HeahDude
Copy link
Contributor

See #19020 for a fix.

fabpot added a commit that referenced this issue Jun 13, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Fixed collapsed choice attributes

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19016
| License       | MIT
| Doc PR        | ~

Commits
-------

445dcc8 [Form] Fixed collapsed choice attributes
@fabpot fabpot closed this as completed Jun 13, 2016
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

5 participants
0