Symfony (Silex) 无线电选择表单生成器不呈现属性 [英] Symfony (Silex) radio choice form builder does not render attr

查看:32
本文介绍了Symfony (Silex) 无线电选择表单生成器不呈现属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为渲染的收音机添加属性

$builder->add('myRadios', 'choice', array('选择' =>大批('一个' =>'uno','两个' =>'到期的'),'多个' =>错误的,'属性' =>数组('class' => 'testClass'),'扩展' =>真的

输出为:

<label class="control-label required">Myradios</label><div class="控件"><label for="form_one_0" class="required radio"><input type="radio" id="form_one_0" name="form[one]" required="required" value="uno"/><span>Uno</span><label for="form_two_1" class="required radio"><input type="radio" id="form_two_1" name="form[two]" required="required" value="due"/><span>到期</span>

没有对 class='testClass' 的引用

我在网上找不到任何问题

解决方案

试试这个方式 Adam,

$form = $app['form.factory']->createBuilder('form')->add('myRadios', 'choice', array('选择' =>大批('一个' =>'uno','两个' =>'到期的'),'多个' =>错误的,'扩展' =>真的,'属性' =>数组('class' => 'testClass'),))->getForm();

它有效:

<input type="radio" id="form_myRadios_0" name="form[myRadios]" required="required" value="one"><label for="form_myRadios_0" class="required">uno</label><input type="radio" id="form_myRadios_1" name="form[myRadios]" required="required" value="two"><label for="form_myRadios_1" class="required">到期</label>

I'm trying to add attributes to my rendered radios

$builder
    ->add('myRadios', 'choice', array(
        'choices' => array(
            'one' => 'uno',
            'two' => 'due'),
        'multiple' => false,
        'attr' => array('class' => 'testClass'),
        'expanded' => true

the output is:

<div class="control-group">
    <label class="control-label required">Myradios</label>
    <div class="controls">
        <label for="form_one_0" class="required radio">
            <input type="radio" id="form_one_0" name="form[one]" required="required" value="uno" />
            <span>Uno</span>
        </label>
        <label for="form_two_1" class="required radio">
            <input type="radio" id="form_two_1" name="form[two]" required="required" value="due" />
            <span>Due</span>
        </label>
    </div>
</div>

no references to class='testClass'

I can't find any issue online

解决方案

Try this way Adam,

$form = $app['form.factory']->createBuilder('form')
        ->add('myRadios', 'choice', array(
            'choices' => array(
                'one' => 'uno',
                'two' => 'due'),
            'multiple' => false,
            'expanded' => true,
            'attr' => array('class' => 'testClass'),
        ))
        ->getForm();

it works:

<div id="form_myRadios" class="testClass">
     <input type="radio" id="form_myRadios_0" name="form[myRadios]" required="required" value="one">
     <label for="form_myRadios_0" class="required">uno</label>
     <input type="radio" id="form_myRadios_1" name="form[myRadios]" required="required" value="two">
     <label for="form_myRadios_1" class="required">due</label>
</div>

这篇关于Symfony (Silex) 无线电选择表单生成器不呈现属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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