Symfony-2 给出不止一个验证错误消息 [英] Symfony-2 gives more than one validation error message
问题描述
给出了我的validation.yml:
My validation.yml is given:
task:
- Email:
message: The email "{{ value }}" is not a valid email.
- MinLength: { limit: 50, message: You must be 50 or under to enter. }
我的问题是,如果我在任务字段中给出错误的电子邮件",它会给出两条错误消息:
My issue is that if I give "wrong-email" in the task-field it gives two error messages:
The email "wrong-email" is not a valid email.
You must be 50 or under to enter.
实际上,我想一次只显示一条错误消息.这意味着只有当它是一个有效的电子邮件时,它才应该检查验证MinLength".
Actually, I want to show only one error-message at a time. That means it should check for the validation "MinLength" only if it is a valid email.
推荐答案
可以使用组序列来完成验证排序.我今天才修复了 YAML 驱动程序的组序列,因此您可能需要等待 2.0 或 master 分支的下一个版本.
Validation sequencing can be done using group sequences. I fixed group sequences for the YAML driver only today, so you might need to wait for the next release of the 2.0 or master branch.
MyEntity:
group_sequence: [MyEntity, Extra]
properties:
task:
- Email: { message: ... }
- MinLength { limit: 50, message: ..., groups: Extra }
现在,只有在组MyEntity"(即默认组)中的所有约束都成功时,才会验证Extra"组中的约束.
Now the constraints in group "Extra" will only be validated if all constraints in group "MyEntity" (i.e. the default group) succeed.
这篇关于Symfony-2 给出不止一个验证错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!