2013-07-02 2 views
0

양식 내에서 cascade_validation을 사용하려고 시도하지만 작동하지 않습니다. 나는 질문의 colection입니다이 엔티티 Formulario이 때문에 Formulario 이런 식으로 형성 내부에 나는 질문 양식을 삽입합니다양식 내의 계단식 유효화 양식

class FormularioType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 

     $builder 
      ->add('nombre') 
      ->add('preguntasPonderadas', 'collection', array(
       'type' => new QuestionType(), 
       'allow_add'=>true, 
       'allow_delete'=>true, 
       'cascade_validation'=>true, 
      )) 
     ;  
    } 
} 

엔티티 문제는이 같은 어설있다을 :

class Question 
{ 
    /** 
    * @var integer 
    * 
    * @Assert\Range(
    *  min = 1, 
    *  max = 5, 
    *  minMessage = "El valor mínimo es 1", 
    *  maxMessage = "El valor máximo es 5" 
    *) 
    * 
    * @ORM\Column(name="peso", type="integer") 
    * 
    */ 
    private $peso; 
} 

문제는 질문 형식에서 질문을 만들면 질문 엔터티의 범위 주장이 작동하지만 Formulario 양식 내에 질문을 만들면 작동하지 않고 범위를 벗어나는 숫자를 허용한다는 것입니다. 빈 필드 제약 조건이 작동하고 cascade_validation을 사용하지 않아도 유효하지 않은 유형이 작동합니다 (예 : 문자를 쓰는 경우).

문제는 범위 제한이 Formulario 양식에서 작동하지 않는다는 것입니다.

어떤 아이디어 ?? Thansk 많이 !!!!

답변

1

또한 FormularioType 클래스의 'cascade_validation' => true 기능을 기능에 추가해야 작동됩니다.

/** 
* Sets the default options for this type. 
* 
* @param OptionsResolverInterface $resolver The resolver for the options. 
*/ 
public function setDefaultOptions(OptionsResolverInterface $resolver) 
{ 
    $resolver->setDefaults(array(
     'data_class' => 'Formulario', 
     'cascade_validation' => true 
    )); 
}