Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form-wide error_bubbling in Symfony 2?

Tags:

php

symfony

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?

like image 989
vinnylinux Avatar asked Apr 25 '12 19:04

vinnylinux


2 Answers

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.

like image 195
JF Simon Avatar answered Oct 31 '22 23:10

JF Simon


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,
        ]);
    }
}
like image 40
Andrew Atkinson Avatar answered Oct 31 '22 21:10

Andrew Atkinson