重写symfony无线电部件 [英] Overriding symfony radio widget
问题描述
默认广播小部件创建以下结构:
Default radio widget creates a following structure:
<label>...</label>
<div id="...">
<div class="clearfix prettyradio labelright blue">
<input type="radio" id="..._0" name="..." value="..." style="display: none;">
<a href="#" class=""></a>
...
</div>
我找到了radio_widget块,但它只包含一个输入本身。所以我可以自定义这个部分:
I found the radio_widget block, but it contains only an input itself. So I can customize there only this part:
<input type="radio" id="..._0" name="..." value="1" style="display: none;">
但我无法理解如何改变整个无线电选择领域的结构?
But I can't understand how to change whole the structure of radio choice field?
另外,有人知道,为什么symfony增加显示:无输入?
Also, does anybody knows, why symfony adds display:none to the input?
谢谢。
推荐答案
如果您使用 Radio Field Type ,你只能自定义 radio_widget
输入部分>通过调用 form_widget(form.yourField)
来阻止,它显示的是,
if you're using Radio Field Type, you can customize only the input
part of the radio_widget
block by calling form_widget(form.yourField)
, all it displays is,
{% block radio_widget %}
{% spaceless %}
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
{% endspaceless %}
{% endblock radio_widget %}
您正在使用选择字段类型显示无线电字段(expanded => true和multiple => false)
。然后您必须重写 choice_widget
块,该块要求每个子元素包含全局环绕的 radio_widget
块 div
But if you're using Choice Field Type to display Radio Fields (expanded => true and multiple => false)
. You'll then have to override the choice_widget
block, which call for each child element the radio_widget
block surrounded by a global div
您是如何得到display:none的?因为在默认区块中没有这样的风格。
How did you get the "display:none"? because there's no style such this in the default block.
这篇关于重写symfony无线电部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!