13

This is how i currently activate errors on my forms:

public function buildForm(FormBuilder $builder, array $options)
{
    $builder
        ->add('title', null, array('error_bubbling' => true))
        ->add('content', null, array('error_bubbling' => true))
    ;
}

Is there a form-wide version?

j0k
  • 22,600
  • 28
  • 79
  • 90
vinnylinux
  • 7,050
  • 13
  • 61
  • 127
  • 1
    I'd be interested in the answer to this... I looked into it briefly before and iirc, I tried `FormBuilder::setErrorBubbling()`; however, I don't remember that it worked. I *think* this is a setting to tell subform errors to bubble up to the parent but I could be wrong. – Darragh Enright Apr 25 '12 at 19:22

2 Answers2

4

No. In general you dont need to make errors bubble to parent form. If you want to display all errors in one place, you can do this in the template.

JF Simon
  • 1,235
  • 9
  • 13
  • 24
    This certainly sucks... i'm not really asking about error display, but enabling error output so getErrors() doesn't come empty. – vinnylinux Apr 26 '12 at 15:16
1

If you are using the form types correctly (maybe don't let symfony guess it) then you should get error bubbling by default as seen here:

http://symfony.com/doc/current/reference/forms/types/text.html#error-bubbling

However If you are using a custom form type then you can set the default error_bubbling by default with configureOptions

final class CustomFormType extends AbstractType
{
    /** {@inheritdoc} */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        ...
    }

    /** {@inheritdoc} */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setRequired('label');
        $resolver->setDefaults([
            'error_bubbling' => false,
            'compound' => true,
        ]);
    }
}
Andrew Atkinson
  • 4,103
  • 5
  • 44
  • 48