php - Symfony 2 form cascading validation -


i have form in symfony 2 like:

$form = $this->createformbuilder();          $form             ->add('subscription', 'entity', array(                 'class' => 'acmedemobundle:subscription',                  'property'              => 'name',                 'label'                 => 'subscription',                 'cascade_validation'    => false,                 'constraints'           => array(                     new notblank(),                 )             )) 

this failing validation error:

subscription: error: value should of type integer. error: value should of type integer. 

the problem don't want cascade validation subscription entity. want able select entity dropdown.

any idea?

the reason getting error messages because you're failing type validation on 1 or more properties of child entity. review constraints wherever you've defined them. in case, error triggered when assigned "type()" constraint on properties allowed null. removing type constraints eliminated errors.

regarding validation of child objects, should happen when assign "valid" constraint on property within parent class, based on reading of documentation. however, appears controlled cascade_validation field defined in setdefaultoptions() method of related abstracttype form type class, can override passing in via $options array @ time instantiate form object:

$form = $this->createform(     $formtype,     $formmodel,     array('cascade_validation' => false) ); 

in case, cascade_validation setting you've defined applies properties of subscription child of form object, think you're trying apply validation setting class (the class has subscription object 1 of properties). change form builder instance this:

$form = $this->createformbuilder(null, array('cascade_validation' => false)); 

alternatively, can explicitly define fields want validated within controller illustrated in symfony2 documentation follows:

use symfony\component\validator\constraints\email;  public function addemailaction($email) {     $emailconstraint = new email();     // constraint "options" can set way     $emailconstraint->message = 'invalid email address';      // use validator validate value     $errorlist = $this->get('validator')->validatevalue(         $email,         $emailconstraint     );      if (count($errorlist) == 0) {         // valid email address,     } else {         // *not* valid email address         $errormessage = $errorlist[0]->getmessage();          // ... error     }      // ... } 

reference documentation on symfony2 validation


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -