Symfony形式的单选之间的换行(< br>) [英] Newline (<br>) between radio choices in Symfony form

查看:181
本文介绍了Symfony形式的单选之间的换行(< br>)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此表单生成代码..

I have this form generation code..:

$form = $this->createFormBuilder($task)
            ->add('mode', 'choice', array(
                'label' => false,
                'choices' => array(
                  'mode1' => '1',
                  'mode2' => '2',
                  'mode3' => '3',
                ),
                'multiple' => false,
                'expanded' => true,
                'required' => true,
            ))
            ->getForm();

问题在于呈现的表单具有内联的选择(无线电输入),它们之间没有<br/>标签.

The problem is that rendered form has choices (radio inputs) inline, without <br/> tags between them.

此外,我无法找到如何使用树枝模板渲染表单,因此不要触摸PHP代码,例如,如何在单选按钮列表中专门装饰" 每个选择.

Also, i cannot find how do i render form with a twig template so do not touch PHP code, for example, how can i specially 'decorate' each choice in my radio buttons list.

 <div style='margin:25px'>
            {{ form_start(form_options) }}
            {{ form_widget(form_options) }}
            {{ form_end(form_options) }}
        </div>

我该如何扩展?

推荐答案

您可以根据需要呈现每个表单字段.不要使用{{ form_widget(form_options) }}使用{{ form_row (form.fieldName) }},然后您可以根据需要添加html和样式:这是一个示例:

You can render each form field as you like. Do not use {{ form_widget(form_options) }} use {{ form_row (form.fieldName) }} then you can add html and style as you like : This is an exemple :

<div class="checkbox-list">
<label class="checkbox-inline col-md-6">
    <div class="checker" id="uniform-inlineCheckbox21">
        <span class="">
            {{form_row(form.fieldName)}}
        </span>
    </div> 
    fieldName
</label>

您还可以传递对象列表并手动创建输入:

You can also pass a list of object and create manually your input :

{% for language in languages %}
<div class="checkbox-list">
    <label class="checkbox-inline col-md-6">
        <div class="checker" id="uniform-inlineCheckbox21">
            <span class="">
                <input type="checkbox"  name="langues[]" id="course{{loop.index}}" value="{{language.id}}" data-title="{{language.designation}}">
            </span>
        </div> 
        {{language.designation}}
    </label>
</div>
{% endfor %}

最后一个解决方案是您可以使用form_theme并通过symfony覆盖options小部件用户: http://symfony.com/fr/doc/current/cookbook/form /form_customization.html

Last solution you can use form_theme and override the choices widget user by symfony : http://symfony.com/fr/doc/current/cookbook/form/form_customization.html

这篇关于Symfony形式的单选之间的换行(&lt; br&gt;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆