-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Comments
Is there a workaround for this issue ? |
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. |
We could use fieldsets for example: #6584 |
π |
1 similar comment
π |
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. |
π need this feature |
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 -%} |
Thanks a lot MaxE17677 it works for me after changing form theme to bootstrap3 |
@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 |
This issue dates back to 2012. I am stuck with SF 3.3. |
closing here in favour of #19514 |
When using
"expanded" => true
on achoice
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
'schoices
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 achoices
variable like that of a collapsed choice field, but currently there is no effective way to match up theChoiceView
object with the corresponding childFormView
in the template, so rendering the fields from thechoices
variable as with a collapsed choice field is not a viable option.The text was updated successfully, but these errors were encountered: