Search code examples
formssymfonysymfony2-easyadmin

Symfony 3 - Form collection field error displaying outside the field


Could anyone tell me why error related to form collection is displaying outside the particular field and how to move it to place like you see in image included below?

enter image description here

Code of this field:

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

Config:

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

I'm using EasyAdminBundle and here's my whole project: https://github.com/ktrzos/SymfonyBasic. Problem applies to "Notimeo\PageBundle".


Solution

  • I see other errors are places above the input fields, so unless this is somehow positioned using CSS (which is very unlikely) it looks like the error is related to the form itself and not the input field. That's the same type of error like invalid CSRF token for example.

    Your issue is probably related to Form Collection error bubbling where poster asks basically the same question as you.

    The recommendation is to set:

    cascade_validation' => true
    

    Or, if you are using Symfony 3:

    error_bubbling  => false