bug #26590 Make sure form errors is valid HTML (Nyholm)

This PR was merged into the 3.4 branch.

Discussion
----------

Make sure form errors is valid HTML

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26461
| License       | MIT
| Doc PR        |

Using `<div>` and `<ul>` in a `<label>` is not valid HTML. This PR uses `<span>`s instead and some Bootstrap 4 classes to make it look just like before.

Commits
-------

5dcaaadb5e Make sure form errors is valid HTML
This commit is contained in:
Fabien Potencier 2018-03-18 20:24:00 +01:00
commit 6c81b6df3c
3 changed files with 28 additions and 36 deletions

View File

@ -267,12 +267,12 @@
{% block form_errors -%}
{%- if errors|length > 0 -%}
<div class="{% if form is not rootform %}invalid-feedback d-block{% else %}alert alert-danger{% endif %}">
<ul class="list-unstyled mb-0">
{%- for error in errors -%}
<li><span class="initialism form-error-icon badge badge-danger">{{ 'Error'|trans({}, 'validators') }}</span> <span class="form-error-message">{{ error.message }}</span></li>
{%- endfor -%}
</ul>
</div>
<span class="{% if form is not rootform %}invalid-feedback d-block{% else %}alert alert-danger{% endif %}">
{%- for error in errors -%}
<span class="mb-0 d-block">
<span class="initialism form-error-icon badge badge-danger">{{ 'Error'|trans({}, 'validators') }}</span> <span class="form-error-message">{{ error.message }}</span>
</span>
{%- endfor -%}
</span>
{%- endif %}
{%- endblock form_errors %}

View File

@ -32,14 +32,12 @@ abstract class AbstractBootstrap4HorizontalLayoutTest extends AbstractBootstrap4
[
./label[@for="name"]
[
./div[
./ul
[./li
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error![/trans]"]]
]
[count(./li)=1]
]
./span[@class="alert alert-danger"]
[./span[@class="mb-0 d-block"]
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error![/trans]"]]
]
[count(./span)=1]
]
/following-sibling::div[./input[@id="name"]]
]

View File

@ -32,14 +32,12 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest
[
./label[@for="name"]
[
./div[
./ul
[./li
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error![/trans]"]]
]
[count(./li)=1]
]
./span[@class="alert alert-danger"]
[./span[@class="mb-0 d-block"]
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error![/trans]"]]
]
[count(./span)=1]
]
/following-sibling::input[@id="name"]
]
@ -162,22 +160,18 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest
$html = $this->renderErrors($view);
$this->assertMatchesXpath($html,
'/div
'/span
[@class="alert alert-danger"]
[
./ul
[@class="list-unstyled mb-0"]
[
./li
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error 1[/trans]"]]
/following-sibling::li
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error 2[/trans]"]]
]
[count(./li)=2]
./span[@class="mb-0 d-block"]
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error 1[/trans]"]]
/following-sibling::span[@class="mb-0 d-block"]
[./span[.="[trans]Error[/trans]"]]
[./span[.="[trans]Error 2[/trans]"]]
]
[count(./span)=2]
'
);
}