开发者

How to override default validation message of entity choice field?

开发者 https://www.devze.com 2023-04-03 18:33 出处:网络
I have defined foreign key in my User entity: /** * @ORM\\ManyToOne(targetEntity=\"Region\") */ protected $region;

I have defined foreign key in my User entity:

/**
 * @ORM\ManyToOne(targetEntity="Region")
 */
protected $region;

I'd like to use it in form as a choice field.

$builder->add('region');

Which works great in fact, until I want to validate if choice is valid entity id. In fact, that works great too, but I'm getting This value is not valid error message and I need to override / translate it and I have no idea how. It's some kind of aut开发者_StackOverflow中文版omatic validation. Logically, I'd say it should be overridable if I set @Assert\Choice..., but even when I tried it with dummy values (message="You shall not pass", choices={1,2}), it seemed to ignore it completely.


Use the message parameter:

@Assert\Choice(message="This is not a valid region")

Or the multipleMessage parameter, if you allow multiple choices:

@Assert\Choice(multipleMessage="...")

See http://symfony.com/doc/2.0/reference/constraints/Choice.html

0

精彩评论

暂无评论...
验证码 换一张
取 消