It seems to be easy but I cannot succeed into doing it. I have choices element. I want them to display only the value I set and not the default value (or empty value).
How can I achieve this?
To disable empty value, try this:
$builder->add('states', 'choice', array(
'empty_value' => false,
));
If you leave the empty_value option unset, then a blank (with no text) option will automatically be added if and only if the required option is false.
For Symfony 2.6+ please use 'placeholder' => false option to avoid empty value.
$builder->add('states', 'choice', array(
'placeholder' => false,
));
http://symfony.com/doc/current/reference/forms/types/choice.html#placeholder
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