forms - Add validation constraints on mapped = false fields for a specific validation group -


i'd able add in form class additional validation constraints specific validation group. how ?

since symfony 2.1, adding validation while building form looks :

use symfony\component\validator\constraints\minlength; use symfony\component\validator\constraints\notblank;  $builder     ->add('firstname', 'text', array(         'constraints' => new minlength(3),     ))     ->add('lastname', 'text', array(         'constraints' => array(             new notblank(),             new minlength(3),         ),     )) ; 

sources

is there way assign them validation constraint ?

in case, have validation groups depending on submitted data

thanks in advance suggestions

ok, solution pretty straighforward actually.

looking @ constraint class, noticed exposed $groups property , addimplicitgroupname(string $group) method.

when know that, know it:

$cv1 = new notblank(); $cv1->groups = array('mygroup'); $cv2 = new notnull(); $cv2->groups = array('mygroup'); $mycnstrs = array(     'constraints' => array(          $cv1,          $cv2,      ) );  $myotheroptions = array(      ... );  $builder->add('myfield', null, array_merge($mycnstrs,$myotheroptions)); 

sorry if abused posting question , replying right after...


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -