Skip to content

Add cookbook chapter on error_bubbling and dealing with form errors in twig #6145

@webdevilopers

Description

@webdevilopers

@weaverryan from @KnpLabs posted a nice article here:
https://knpuniversity.com/blog/symfony-debugging-form-errors

Originally I came from the following issue: symfony/symfony#17363

The described issue caused a strange effect in which non mapped field errors were linked to the parent form - the same thing that would have happened if you turned error_bubbling to true.

Since this I was able to catch the errors from the form.vars array in my template:

{% if form.vars.errors|length > 0 %}

After i solved the issue the errors were correctly removed from the bubble and attached to the assigned field. My twig condition would no longer work. I had to change it:

{% if not form.vars.valid %}

I've seen a lot of questions on SO on this e.g.:

Actually I havn't found any chapter that explains what error_bubbling is in the first place.
Most of the times it is described directly inside a form field type or collection.

I think the cookbook could really be improved with this. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions