From d8f3de91d5907df505281803c482fd7edb2b5eb7 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 18 Mar 2018 15:50:20 +0100 Subject: [PATCH] Make sure we always render errors. Eventhough labels are disabled --- .../Resources/views/Form/bootstrap_4_layout.html.twig | 6 ++++++ .../Form/Tests/AbstractBootstrap4LayoutTest.php | 10 ++++++++++ 2 files changed, 16 insertions(+) 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..e2061c29ba 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 @@ -204,6 +204,12 @@ {%- endif -%} {%- endif -%} <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{{- form_errors(form) -}} + {%- else -%} + {%- if errors|length > 0 -%} +
+ {{- form_errors(form) -}} +
+ {%- endif -%} {%- endif -%} {%- endblock form_label %} diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php index ec97577818..b9e8a38e0f 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php @@ -182,6 +182,16 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest ); } + public function testErrorWithNoLabel() + { + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', array('label'=>false)); + $form->addError(new FormError('[trans]Error 1[/trans]')); + $view = $form->createView(); + $html = $this->renderLabel($view); + + $this->assertMatchesXpath($html, '//span[.="[trans]Error[/trans]"]'); + } + public function testCheckedCheckbox() { $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', true);