Symfony2 - form_widget - 复选框分开
Symfony2 - form_widget - checkbox separate
我有这个:
<fieldset>
<legend>{{ form_label(form.fees, 'fees' | trans , { 'label_attr': {'class': 'col-sm-3 control-label'} }) }}</legend>
<div class="large-12 columns fees">
<br/>
{{ form_errors(form.fees) }}
<div class="col-sm-5">
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}
</div>
</div>
</fieldset>
这一行:
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}
打印:
<label></label>
<input />
<label></label>
<input />
但我需要这样的东西(带包装):
<div><label></label><input /></div>
<div><label></label><input /></div>
谢谢!! :)
如果您想要一行四个复选框,则类似于:
{# Wrap span around checkboxes #}
{{ form_label(form.fees) }}
{{ form_errors(form.fees) }}<br>
{% for batch in form.fees|batch(4) %}
<div class="batchRow">
{% for option in batch %}
<div class="yourClassName">
{{ form_label(option) }}
{{ form_widget(option) }}
</div>
{% endfor %}
</div>
{% endfor %}
否则可以去掉batch level
您可以使用自定义单个字段。例如,您有 ProductType
表格,您的案件是收费的。因此,您可以在顶部代码中添加这一行:
{# tell symfony use form theme #}
{% form_theme form _self %}
{# the block customize #}
{% block _product_fees_widget %}
<div>
{{ block('form_widget_simple') }}
</div>
{% endblock %}
{# print #}
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}
更多信息,请阅读这篇文章FORM THEME
我有这个:
<fieldset>
<legend>{{ form_label(form.fees, 'fees' | trans , { 'label_attr': {'class': 'col-sm-3 control-label'} }) }}</legend>
<div class="large-12 columns fees">
<br/>
{{ form_errors(form.fees) }}
<div class="col-sm-5">
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}
</div>
</div>
</fieldset>
这一行:
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}
打印:
<label></label>
<input />
<label></label>
<input />
但我需要这样的东西(带包装):
<div><label></label><input /></div>
<div><label></label><input /></div>
谢谢!! :)
如果您想要一行四个复选框,则类似于:
{# Wrap span around checkboxes #}
{{ form_label(form.fees) }}
{{ form_errors(form.fees) }}<br>
{% for batch in form.fees|batch(4) %}
<div class="batchRow">
{% for option in batch %}
<div class="yourClassName">
{{ form_label(option) }}
{{ form_widget(option) }}
</div>
{% endfor %}
</div>
{% endfor %}
否则可以去掉batch level
您可以使用自定义单个字段。例如,您有 ProductType
表格,您的案件是收费的。因此,您可以在顶部代码中添加这一行:
{# tell symfony use form theme #}
{% form_theme form _self %}
{# the block customize #}
{% block _product_fees_widget %}
<div>
{{ block('form_widget_simple') }}
</div>
{% endblock %}
{# print #}
{{ form_widget(form.fees, { 'attr': {'class': 'form-control validate[required]'} }) }}
更多信息,请阅读这篇文章FORM THEME