-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Halt subsequent constraints on first failure #2947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is indeed an undocumented feature and can be achieved using group sequences. In group sequences, you can define validation groups to be validated in order. Once a group fails, further groups won't be validated.
Does this solve your issue? |
@bschussek you should contribute to the doc. I think even most core devs ignored about this feature. |
@bschussek the group sequence thing is that per property or will it be skipped for the whole object? |
@henrikbjorn It's for the whole object. One group must validate completely (constraints on the object and all of its properties in this group) in order to allow for the next group to be validated. |
@bschussek If you don't have time to contribute full-features docs, please at least write some wireframe the community could expand by hacking around. I'm using Symfony2 daily and didn't know about this feature. |
@marcw I'll see what I can do. I have some time throughout the next days. |
@bschussek thanks! |
I know how to set group_sequence for a form in yml config and for a form class. But how to set groupSequence in dynamic forms ?. My example: $this->createFormBuilder(null, array(
'validation_constraint' => new Collection(array(
'randominput' => array(
new Email(),
new MyCustomConstraint()
)
))
->add('randominput', 'text'); Help please (sorry for my english) |
I think it will be muuch easier and cleaner for me just to set one parameter for an input, for example /** @GroupSequence({"g1", "g2", "g3", ...}) */
class MyClass
{
/**
* @NotBlank(groups="g1")
* @Regex(pattern="...", groups="g2")
* @Email(groups="g3")
* @...
*/
private $property;
} My idea is so simple: I have set some constraints for an input, I want they to be applied in order I set them in array and if some constraint finds a violation, skip the rest. Why do I have to validate thru the rest of the constraints because it's clear that the input value is not valid anymore? |
@moldcraft, you may create a custom validator, which will stop at the first violation (example). |
Let's say that an entity have the following constraints applied to a property:
When a form validates the propery:
I understand that this was the desired default behaviour, but for some use cases one would want to halt on first failure.
I remember that symfony1.x had the halt_on_error option for this, though I couldn't found any reference to achieve this in symfony2.
Is this an undocumented feature? or is this still not implemented?
The text was updated successfully, but these errors were encountered: