Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Form errors rendered twice for one field. #29187

Closed
@jawadmjn

Description

@jawadmjn

Symfony version(s) affected: 4.1

Description
It occurs in this commit

By putting errors in the label now the following issue occurs. And we can not use Customize Form Rendering

For example when I am putting a field like this:

{{ form_label(attraction.surroundings) }}

{{ form_widget(attraction.surroundings) }}

{{ form_help(attraction.surroundings) }}

{{ form_errors(attraction.surroundings) }}

And Error occured then The error message is one time showing in label and 2nd time what i put form_errors.

screen shot 2018-11-12 at 13 57 11

Possible Solution
So we should take errors out from the label and have to put form_errors in form_row And we have to put form_errors in the end otherwise if the error occurs then error area will push the whole layout down.

{% block form_row -%}
    {%- if compound is defined and compound -%}
        {%- set element = 'fieldset' -%}
    {%- endif -%}
    {%- set widget_attr = {} -%}
    {%- if help is not empty -%}
        {%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
    {%- endif -%}
    <{{ element|default('div') }} class="form-group">
        {{- form_label(form) -}}
        {{- form_widget(form, widget_attr) -}}
        {{- form_help(form) -}}
        **{{- form_errors(form) -}}**
    </{{ element|default('div') }}>
{%- endblock form_row %}

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