防止无线电小部件使用 Symfony2 渲染标签 [英] Prevent radio widgets from rendering labels with Symfony2
本文介绍了防止无线电小部件使用 Symfony2 渲染标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在没有标签的情况下渲染这个表单元素,但我找不到方法...
I have this form element I want to render without a label, but I can't find the way...
$builder
->add('gender', 'choice', array(
'expanded' => true,
'choices' => array(
'Male' => 'm',
'Female' => 'f',
)
))
;
请帮忙,这是行不通的:
some help please, this isn't working:
{% block choice_widget %}
{% spaceless %}
{% for child in form %}
<input type="radio" value="{{ child.get('value') }}">
{% endfor %}
{% endspaceless %}
{% endblock choice_widget %}
我正在获取数组到字符串的转换
我想做的是一个基于图片的性别选择器,只需点击图片即可进行选择.
What I wanna do is an image based gender selector, just clicking an image to make the selection.
推荐答案
当使用表单组件时,不要自己渲染表单域,总是依赖 form_
帮助器,如
When using the form component, do not ever render form fields yourself, always rely on the form_
helpers as described in the form documentation.
在你的情况下,这应该有效:
In your case, this should work:
{{ form_label(form.gender) }}
{{ form_errors(form.gender) }}
{% for choiceFormView in form.gender %}
{{ form_widget(choiceFormView) }}
{% endfor %}
这篇关于防止无线电小部件使用 Symfony2 渲染标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文