Reputation: 3158
Building a Symfony2 form with choices, there is a option "empty value", to set the text related to the empty choice.
However, I want to set my choice field as mandatory, so the empty value should be displayed but no choosen. Using the empty or null constraints, there is no error when the user send the "" value. How should this be done?
Upvotes: 1
Views: 1423
Reputation: 3158
Sorry for inconvenience, I had a listener that overwrote the constraint I set before for choices only, that's why it didn't work like it should...
Upvotes: 0
Reputation: 14136
You can add a NotBlank()
validation constraint to the appropriate property in the form's underlying entity.
How you do this depends on whether you are using annotations or yaml for your validation definitions.
There is some information about the validator here:
http://symfony.com/doc/current/reference/constraints/NotBlank.html
Hope this helps :)
Upvotes: 2