symfony 2.2 - Stop validation on first error flag in Symfony2? -
i'm searching informations if there kind of flag/option force symfony2 validation stop on first error in validation chain. example have 3 validators on email field:
email: - notblank: { groups: [ send_activation_email ] } - length: { min: 6, max: 80, charset: utf-8, groups: [ send_activation_email ] } - email: { groups: [ send_activation_email ] } i want stop validation after first error. how can achieve that? read similar questions:
symfony2 : validation halt on first error
how stop validation on constraint failure in symfony2
symfony-2 gives more 1 validation error message
last 1 quite there way without using validation groups every time, when there more 1 validator? read somewhere in symfony 2.2 there flag or option this, have 2.2.1 version , can't find such option.
you can use chain validator purpose: https://gist.github.com/rybakit/4705749
here's example in plain php:
<?php use symfony\component\validator\constraints\date; use symfony\component\validator\constraints\type; use acme\validator\constraints\chain; $constraint = new chain([new type('string'), new date()]); in xml:
<!-- src/acme/demobundle/resources/config/validation.xml --> <class name="acme\demobundle\entity\acmeentity"> <property name="date"> <constraint name="acme\validator\constraints\chain"> <option name="constraints"> <constraint name="type"> <option name="type">string</option> </constraint> <constraint name="date" /> </option> </constraint> </property> </class> but aware if want have nested chain constraints, like:
<?php $constraint = new chain([ new callback(...), new chain([new type('string'), new date()]), ]); you have override validator.validator_factory symfony service fix issue handling nested constraints in current implementation: https://github.com/symfony/validator/blob/fc0650c1825c842f9dcc4819a2eaff9922a07e7c/constraintvalidatorfactory.php#l48.
see nocacheconstraintvalidatorfactory.php file gist idea how solved.
Comments
Post a Comment