如何设置选择标签元素的类?

时间:2016-02-04 03:32:38

标签: forms symfony styles

如何为选择元素添加标签类?如果不在树枝模板中进行,这甚至是可能的吗?

呈现表单选择元素:

<div>
    <label class="required">Type</label>
    <div id="AddNewAdType_type">
        <input type="radio" id="AddNewAdType_type_0" name="AddNewAdType[type]" required="required" value="b">
        <label for="AddNewAdType_type_0" class="required">one</label> // add  css class here
        <input type="radio" id="AddNewAdType_type_1" name="AddNewAdType[type]" required="required" value="s">
        <label for="AddNewAdType_type_1" class="required">two</label> // add css class here
    </div>  
</div>

例如:

//...
    ->add("currency", "choice",[
            'choices'=>[
                '1' => 'one',
                '2' => 'two'
            ],
        'expanded' => true,
        'choice_attr' =>[
            'class' => 'cssClassName' //won't work
            ]
    ])
//...

1 个答案:

答案 0 :(得分:-1)

 ->add("currency", "choice",[
            'choices'=>[
                '1' => 'one',
                '2' => 'two'
            ],
        'expanded' => true,
        'label_attr' =>[
            'class' => 'cssClassName' 
            ]
    ])

喝彩!