如何勾选复选框?

时间:2012-08-09 03:49:30

标签: symfony

我在表单构建器

中有这个字段
->add('pay_method', 'choice', array(
            'choices' => array(
                'telnet' => 'Image',
            ),
            'expanded' => true,
            'label' => 'Способ оплаты',
        ))

只有一个选项,但我如何检查?

4 个答案:

答案 0 :(得分:0)

使用attr添加'checked' => 'checked'索引:

->add('pay_method', 'choice', array(
        'choices' => array(
            'telnet' => 'Image',
        ),
        'expanded' => true,
        'label' => 'Способ оплаты',
        'attr' => array('checked' => 'checked')
    ))

答案 1 :(得分:0)

将其设置在表单所用的对象或数组上。

答案 2 :(得分:0)

您可以通过在域模型中设置默认值来设置默认值:

private $pay_method = 'telnet';

$object->pay_method = 'telnet'

或通过指定字段的“data”选项:

$builder->add('pay_method', 'choice', array(
    'choices' => array(
        'telnet' => 'Image',
        ...
    ),
    'data' => 'telnet',
    'expanded' => true,
    'label' => ...,
));

答案 3 :(得分:0)

好的,我通过JavaScript

完成了