From 5dcaaadb5e8c01148b67d009c95a5118849f9a55 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 18 Mar 2018 15:29:46 +0100 Subject: [PATCH] Make sure form errors is valid HTML --- .../views/Form/bootstrap_4_layout.html.twig | 14 ++++---- ...AbstractBootstrap4HorizontalLayoutTest.php | 14 ++++---- .../Tests/AbstractBootstrap4LayoutTest.php | 36 ++++++++----------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig index a3484d9036..6b5183592e 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig @@ -261,12 +261,12 @@ {% block form_errors -%} {%- if errors|length > 0 -%} -
- -
+ + {%- for error in errors -%} + + {{ 'Error'|trans({}, 'validators') }} {{ error.message }} + + {%- endfor -%} + {%- endif %} {%- endblock form_errors %} diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php index e8ede167b3..c906c6549a 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php @@ -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"]] ] diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php index ec97577818..aa0600e58f 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php @@ -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] ' ); }