21

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?

1 Answer 1

48

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

Sign up to request clarification or add additional context in comments.

3 Comments

It seems that this option doesn't exist anymore in symfony 3... How can I get the same result ? Thanks...
Ok, I got it, use 'placeholder' => false
Just want translate "None" option in radio in symfony 3.2 'placeholder'=> 'your none option'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.