本文介绍了Symfony2 中的分组复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Symfony2 Form 组件似乎无法处理这种常见情况.下面是我想要的在我的 html
代码如下:
->add('code', 'choice', array('选择' =>大批('食物' =>数组('披萨','汉堡','冰淇淋'),'音乐' =>数组('小马','小','口袋'),),'多个' =>真的,'扩展' =>真的,'必需' =>真的));
实际上给出了错误的输出:
这很奇怪,因为 expanded =>false
正确处理
请问这种情况如何处理?
解决方案
好的,这里是 form_theme 解决方案
{% block _user_code_widget %}<div {{ block('widget_container_attributes') }}>{% 用于名称,form.vars.choices 中的选项 %}<ul><li class="checkbox_category"><input type="checkbox" class="checkallsub"/>{{ 姓名 }}{% for key,choice in choice %}{{ form_widget(form[key]) }}{{ form_label(form[key]) }}{% 结束为 %}{% 结束为 %}
{% 结束块 %}
当然缺少额外的 js 层,但您明白了.
It seems that Symfony2 Form component does not handle this common case. Below is what I want in my html
The code looks like :
->add('code', 'choice', array(
'choices' => array(
'Food' => array('pizza', 'burger', 'icecream'),
'Music' => array('poney', 'little', 'pocket'),
),
'multiple' => true,
'expanded' => true,
'required' => true
));
Which gives in reality the wrong output :
It's wierd because the case with expanded => false
is correctly handled
How to handle that case please ?
解决方案
Ok so here's the form_theme solution for this
{% block _user_code_widget %}
<div {{ block('widget_container_attributes') }}>
{% for name, choices in form.vars.choices %}
<ul>
<li class="checkbox_category">
<input type="checkbox" class="checkallsub" /> {{ name }}
</li>
{% for key,choice in choices %}
<li class="indent">
{{ form_widget(form[key]) }}
{{ form_label(form[key]) }}
</li>
{% endfor %}
</ul>
{% endfor %}
</div>
{% endblock %}
Of course the extra js layer is missing, but you get the idea.
这篇关于Symfony2 中的分组复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!