2016-04-26 53 views
2

任何人都可以告訴我爲什麼與表單集合相關的錯誤在特定字段外部顯示,以及如何將它移動到您在以下圖像中看到的位置?Symfony 3 - 在字段外部顯示錶單集合字段錯誤

enter image description here

本場代碼:

/** 
* @Assert\Valid 
* @ORM\OneToMany(
*  targetEntity="PageFile", 
*  mappedBy="page", 
*  cascade={"persist","remove"}, 
*  orphanRemoval=true 
*) 
* @var PageFile[] 
* @Assert\Count(max="1") 
*/ 
private $pageFiles; 

配置:

   - property: 'pageFiles' 
        type: 'collection' 
        type_options: 
         entry_type: 'Notimeo\PageBundle\Form\Type\MyFileType' 
         by_reference: false 
         error_bubbling: false 

我使用EasyAdminBundle這是我的整個項目:https://github.com/ktrzos/SymfonyBasic。問題適用於「Notimeo \ PageBundle」。

回答

3

我看到其他錯誤上面的輸入字段的地方,所以除非以某種方式使用CSS(這不太可能),位於它看起來像錯誤與形式本身,而不是輸入字段。例如,這是與無效的CSRF令牌相同類型的錯誤。

哪裏海報要求基本相同的問題,你您的問題可能與Form Collection error bubbling

的建議是設置:

cascade_validation' => true 

或者,如果你正在使用的Symfony 3:

error_bubbling => false 
+0

'選項 「cascade_validation」 不exist.' –

+0

我看到,海報正在使用Symfony 2.1。我在這裏使用Symfony 3.0.1。它可以有所作爲。 –

+0

它看起來像在Symfony3中被刪除了,我不知道你使用的是什麼版本。請參閱Symfony 2.8 doc:http://symfony.com/doc/2.8/reference/forms/types/form.html#cascade-validation。他們建議使用有效約束,而不是http://symfony.com/doc/current/reference/constraints/Valid.html – martin

相關問題