Symfony:如何自定义无线电字段选择中出现的"无"标签?

Rou*_*ubi 2 forms symfony

我正在使用"required"=> false的单选按钮.这使得"无"选项与我的其他选择一起出现.

如何自定义此标签(假设我想显示"null"而不是"none")?

Moh*_*yan 12

如果要删除它,请设置placeholder为false

->add('color', ChoiceType::class, array(
    'choices' => array('Red' => 1, 'Blue' => 2, 'Green' => 3),
    'expanded' => true,
    'required' => false,
    'placeholder' => false
));
Run Code Online (Sandbox Code Playgroud)

  • @Michel有趣的是,这正是我所寻找的:-) (2认同)

yce*_*uto 10

使用placeholder选项更改"无"无线电输入的标签:

->add('color', ChoiceType::class, array(
    'choices' => array('Red' => 1, 'Blue' => 2, 'Green' => 3),
    'expanded' => true,
    'required' => false,
    'placeholder' => 'Null', // <---- \o/
));
Run Code Online (Sandbox Code Playgroud)

预习:

没有无线电输入

占位符选项是在Symfony 2.6(doc)中引入的