Description
@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.:
- http://stackoverflow.com/questions/8914649/simple-check-if-form-field-has-errors-in-twig-template @lstrojny
- http://stackoverflow.com/questions/22650127/form-errorsform-symfony2-twig
etc.
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?
Activity
carsonbot commentedon Dec 18, 2020
Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?
carsonbot commentedon Jan 1, 2021
Friendly ping? Should this still be open? I will close if I don't hear anything.
webdevilopers commentedon Jan 4, 2021
I'm no longer working with the Form component. Closing.