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 -%} {% block form_errors -%}
{%- if errors|length > 0 -%} {%- if errors|length > 0 -%}
<div class="{% if form is not rootform %}invalid-feedback d-block{% else %}alert alert-danger{% endif %}"> <span 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 -%} {%- 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> <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 -%} {%- endfor -%}
</ul> </span>
</div>
{%- endif %} {%- endif %}
{%- endblock form_errors %} {%- endblock form_errors %}

View File

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

View File

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