2016-04-26 41 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