Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[3.0] [Form] Expanded choice field does not display group headings #5489

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
mlfrazier-xx opened this issue Sep 11, 2012 · 12 comments
Closed

Comments

@mlfrazier-xx
Copy link

When using "expanded" => true on a choice field that contains groups, the default form theme simply renders all radio buttons/checkboxes sequentially, without headings or any other indication of the group structure (at least under Twig).

From what I can tell, this issue stems from the fact that the choices in an expanded choice field are written directly from the FormView's choices variable, which is structured into groups. By contrast, expanded choice fields are represented using a series of checkbox/radio button fields, which are treated as children of the choice field - the problem being that the children are not arranged in any hierarchical structure.

The FormView for an expanded choice field does still have a choices variable like that of a collapsed choice field, but currently there is no effective way to match up the ChoiceView object with the corresponding child FormView in the template, so rendering the fields from the choices variable as with a collapsed choice field is not a viable option.

@mdarse
Copy link

mdarse commented Jun 17, 2014

Is there a workaround for this issue ?

@webmozart
Copy link
Contributor

This could be solved by representing the choice groups as nodes in the form tree with "inherit_data" set to true. However, this would be a BC break.

@webmozart webmozart changed the title [Form] Expanded choice field does not display group headings [3.0] [Form] Expanded choice field does not display group headings Oct 16, 2014
@webmozart
Copy link
Contributor

We could use fieldsets for example: #6584

@patie
Copy link
Contributor

patie commented Nov 8, 2014

πŸ‘

1 similar comment
@webdevilopers
Copy link

πŸ‘

@garak
Copy link
Contributor

garak commented Aug 3, 2015

I see that this issue has been tagged with "[3.0]", even if it dates back to 2012, so I guess that this will be solved in Symfony 3.
Is there any solution for Symfony 2?

@ghost
Copy link

ghost commented Dec 21, 2015

πŸ‘ need this feature

@MaxE17677
Copy link

In Symfony 2.8 the following works for me:

{%- block choice_widget_expanded -%}
     <div {{ block('widget_container_attributes') }}>
        {% for name, choices in form.vars.choices %}
            {% if choices is iterable  %}

            <label class="choice_category">
                <strong>
                    {{ choice_translation_domain is same as(false) ? name : name|trans({}, choice_translation_domain) }}
                </strong>
            </label>
            <div>
            {% for key,choice in choices %}
                {{ form_widget(form[key]) }}
                {{ form_label(form[key]) }}
            {% endfor %}
            </div>

            {% else %}

            {{- form_widget(form[name]) -}}
            {{- form_label(form[name], null, {translation_domain: choice_translation_domain}) -}}

            {% endif %}
        {% endfor %}
{%- endblock choice_widget_expanded -%}

@walidjlidi
Copy link

walidjlidi commented May 9, 2016

Thanks a lot MaxE17677 it works for me after changing form theme to bootstrap3

@TerjeBr
Copy link

TerjeBr commented Nov 7, 2017

@webmozart Could this be solved in the templates like @MaxE17677 did? It seems a lot simpler than using groups of child nodes in the form. What do you think?

If the solution of looping on form.vars.choices in the template, instead of looping on form is an acceptable solution, I could make a PR for you on this.

@HiImJulien
Copy link

This issue dates back to 2012. I am stuck with SF 3.3.
Are there any built-in solutions I missed out on?

@xabbuh
Copy link
Member

xabbuh commented Sep 23, 2018

closing here in favour of #19514

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