I'm using radio buttons with "required" => false. This makes a "none" option appear along with my other choices.
How can I customize this label (let's say I would want to display "null" instead of "none") ?
If you want to remove it set placeholder
to false
->add('color', ChoiceType::class, array(
'choices' => array('Red' => 1, 'Blue' => 2, 'Green' => 3),
'expanded' => true,
'required' => false,
'placeholder' => false
));
Use placeholder
option to change the label for "None" radio input:
->add('color', ChoiceType::class, array(
'choices' => array('Red' => 1, 'Blue' => 2, 'Green' => 3),
'expanded' => true,
'required' => false,
'placeholder' => 'Null', // <---- \o/
));
Preview:
The placeholder option was introduced in Symfony 2.6 (doc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With