2013-09-24 2 views
0

작성한 양식에 한 가지 예외가 있습니다. "비용 절감"을 위해 모델의 기존 속성이이 "새로운 필드"에 사용됩니다. 양식 필드 오류 메시지 무시

내 목표 :

  • 변경 기존 속성
  • 변경 기존 속성
  • 변경 내가 밖으로 일

기존 속성의 오류 메시지의 검증의 레이블 유효성 검사를 추가하고 레이블을 변경하는 방법은 있지만 기존 필드의 오류 메시지를 설정할 위치를 찾을 수없는 것 같습니다.

// MyFormType.php 
<?php 
if (!empty($options['unique']) && $options['unique'] == 'some_variable') { 
    $event->getForm()->add($factory->createNamed('existing_field', 'number', null, array(
     'label'  => 'Number field', 
     'required' => true, 
     'max_length' => 6, 
     'constraints' => array(
      new MinLength(6), 
      new MaxLength(6), 
     ), 
    ))); 
} else { 
    $event->getForm()->add($factory->createNamed('existing_field', 'text', null, array(
     'label' => 'Text field', 
    ))); 
} 

유효성 검사 오류 메시지를 설정할 수있는 필드 옵션 키가 있습니까?

답변

0

MinLengthMaxLength이 2.3에 합쳐져서 2.1 또는 2.2의 복사본으로 실행되지 않지만 이전 2.1 및 2.2 API를 확인한 결과이 기능이 작동합니다.

// MyFormType.php 
<?php 
if (!empty($options['unique']) && $options['unique'] == 'some_variable') { 
    $event->getForm()->add($factory->createNamed('existing_field', 'number', null, array(
     'label'  => 'Number field', 
     'required' => true, 
     'max_length' => 6, 
     'constraints' => array(
      new MinLength(array(
       'limit' => 6, 
       'message' => 'This field must be atleast 6 characters long' 
      )), 
      new MaxLength(array(
        'limit' => 6, 
        'message' => 'This field must be shorter than 6 characters' 
       )), 
     ), 
    ))); 
} else { 
    $event->getForm()->add($factory->createNamed('existing_field', 'text', null, array(
     'label' => 'Text field', 
    ))); 
} 
+0

실제로 길이가 2.1에 추가 된 것으로 보입니다. 그 수업을 당신이 제안한 메시지와 함께 사용했고 지금은 작동합니다. – tolgap