8000 bug #26590 Make sure form errors is valid HTML (Nyholm) · symfony/symfony@6c81b6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c81b6d

Browse files
committed
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 ------- 5dcaaad Make sure form errors is valid HTML
2 parents 2c838f9 + 5dcaaad commit 6c81b6d

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@
267267

268268
{% block form_errors -%}
269269
{%- if errors|length > 0 -%}
270-
<div class="{% if form is not rootform %}invalid-feedback d-block{% else %}alert alert-danger{% endif %}">
271-
<ul class="list-unstyled mb-0">
272-
{%- for error in errors -%}
273-
<li><span class="initialism form-error-icon badge badge-danger">{{ 'Error'|trans({}, 'validators') }}</span> <span class="form-error-message">{{ error.message }}</span></li>
274-
{%- endfor -%}
275-
</ul>
276-
</div>
270+
<span class="{% if form is not rootform %}invalid-feedback d-block{% else %}alert alert-danger{% endif %}">
271+
{%- for error in errors -%}
272+
<span class="mb-0 d-block">
273+
<span class="initialism form-error-icon badge badge-danger">{{ 'Error'|trans({}, 'validators') }}</span> <span class="form-error-message">{{ error.message }}</span>
274+
</span>
275+
{%- endfor -%}
276+
</span>
277277
{%- endif %}
278278
{%- endblock form_errors %}

src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ public function testRow()
3232
[
3333
./label[@for="name"]
3434
[
35-
./div[
36-
./ul
37-
[./li
38-
[./span[.="[trans]Error[/trans]"]]
39-
[./span[.="[trans]Error![/trans]"]]
40-
]
41-
[count(./li)=1]
42-
]
35+
./span[@class="alert alert-danger"]
36+
[./span[@class="mb-0 d-block"]
37+
[./span[.="[trans]Error[/trans]"]]
38+
[./span[.="[trans]Error![/trans]"]]
39+
]
40+
[count(./span)=1]
4341
]
4442
/following-sibling::div[./input[@id="name"]]
4543
]

src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ public function testRow()
3232
[
3333
./label[@for="name"]
3434
[
35-
./div[
36-
./ul
37-
[./li
38-
[./span[.="[trans]Error[/trans]"]]
39-
[./span[.="[trans]Error![/trans]"]]
40-
]
41-
[count(./li)=1]
42-
]
35+
./span[@class="alert alert-danger"]
36+
[./span[@class="mb-0 d-block"]
37+
[./span[.="[trans]Error[/trans]"]]
38+
[./span[.="[trans]Error![/trans]"]]
39+
]
40+
[count(./span)=1]
4341
]
4442
/following-sibling::input[@id="name"]
4543
]
@@ -162,22 +160,18 @@ public function testErrors()
162160
$html = $this->renderErrors($view);
163161

164162
$this->assertMatchesXpath($html,
165-
'/div
163+
'/span
166164
[@class="alert alert-danger"]
167165
[
168-
./ul
169-
[@class="list-unstyled mb-0"]
170-
[
171-
./li
172-
[./span[.="[trans]Error[/trans]"]]
173-
[./span[.="[trans]Error 1[/trans]"]]
174-
175-
/following-sibling::li
176-
[./span[.="[trans]Error[/trans]"]]
177-
[./span[.="[trans]Error 2[/trans]"]]
178-
]
179-
[count(./li)=2]
166+
./span[@class="mb-0 d-block"]
167+
[./span[.="[trans]Error[/trans]"]]
168+
[./span[.="[trans]Error 1[/trans]"]]
169+
170+
/following-sibling::span[@class="mb-0 d-block"]
171+
[./span[.="[trans]Error[/trans]"]]
172+
[./span[.="[trans]Error 2[/trans]"]]
180173
]
174+
[count(./span)=2]
181175
'
182176
);
183177
}

0 commit comments

Comments
 (0)
< 29C5 script type="application/json" id="__PRIMER_DATA_:R0:__">{"resolvedServerColorMode":"day"}
0