Overriding symfony radio widget

醉酒当歌 提交于 2019-12-05 22:35:19

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 %}

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

How did you get the "display:none"? because there's no style such this in the default block.

If you specifically want to override the way an individual radio field is rendered - i.e. how each input field in the group is rendered - use this formula for the block name:

_<form name>_<field name>_entry_widget

Note this bit: _entry

If you're using an expanded choice field ..._entry_row and ..._entry_label won't work because they aren't used for the individual choices - well for radio buttons at least.

More generally you can find out a lot about which block Symfony intends to use during the next call to {{ form_widget(form) }} function call using this code:

{% for b in form.vars.block_prefixes %}
    {{ dump(b) }}
{% endfor %}

or you might want to look at child in some situations:

{% for b in child.vars.block_prefixes %}
    {{ dump(b) }}
{% endfor %}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!