2014-11-06 48 views
0

SectionsType類symfony的表單驗證忽略的消息

/** 
* @param FormBuilderInterface $builder 
* @param array $options 
*/ 
public function buildForm(FormBuilderInterface $builder, array $options) 
{ 

    $builder 
     ->add('name') 
     ->add('description') 
    ; 

} 

/** 
* @param OptionsResolverInterface $resolver 
*/ 
public function setDefaultOptions(OptionsResolverInterface $resolver) 
{ 
    $resolver->setDefaults(array(
     'data_class' => 'Acm\StoreBundle\Entity\Sections' 
    )); 
} 

/** 
* @return string 
*/ 
public function getName() 
{ 
    return 'acm_storebundle_sections'; 
} 

Validation.yml:

Acm\StoreBundle\Entity\Sections: 
properties: 
    name: 
     - NotBlank: 
      message: not.valid 
     - Length: 
      min: 3 
      max: 45 

也是我試過

Acm\StoreBundle\Entity\Sections: 
properties: 
    name: 
     - NotBlank: {message: "not.valid" } 
     - Length: 
      min: 3 
      max: 45 

驗證{}郎.yml:

<body> 
     <trans-unit id="1"> 
      <source>not.valid</source> 
      <target> enter a valid name</target> 
     </trans-unit> 

    </body> 

config.yml

validation:  { enabled: true } 

我試圖

validation:  { enabled: true, enable_annotations: true } 

validation:  { enabled: true, enable_annotations: false } 

validation:  { enable_annotations: true } 

問題是驗證顯示「普萊斯e填寫這個字段。「帶有空條目的消息並忽略Validation.yml文件中的消息

有什麼想法?

+0

是您的YML文件調用驗證?如果是,那就錯了。該名稱必須是驗證器。嘗試清理緩存 – 2014-11-06 19:00:24

+0

感謝joao alves – ghaidaa84 2014-11-09 07:24:17

回答

0

解決方案是增加 「NOVALIDATE」 禁用HTML5驗證

{{ form(form, {'attr': {'novalidate': 'novalidate'}}) }}