8000 Make sure we always render errors. Eventhough labels are disabled · symfony/symfony@d8f3de9 · GitHub
[go: up one dir, main page]

Skip to content

Commit d8f3de9

Browse files
committed
Make sure we always render errors. Eventhough labels are disabled
1 parent 866a142 commit d8f3de9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@
204204
{%- endif -%}
205205
{%- endif -%}
206206
<{{ 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) -}}</{{ element|default('label') }}>
207+
{%- else -%}
208+
{%- if errors|length > 0 -%}
209+
<div id="{{ id }}_errors" class="mb-2">
210+
{{- form_errors(form) -}}
211+
</div>
212+
{%- endif -%}
207213
{%- endif -%}
208214
{%- endblock form_label %}
209215

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ public function testErrors()
182182
);
183183
}
184184

185+
public function testErrorWithNoLabel()
186+
{
187+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', array('label'=>false));
188+
$form->addError(new FormError('[trans]Error 1[/trans]'));
189+
$view = $form->createView();
190+
$html = $this->renderLabel($view);
191+
192+
$this->assertMatchesXpath($html, '//span[.="[trans]Error[/trans]"]');
193+
}
194+
185195
public function testCheckedCheckbox()
186196
{
187197
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', true);

0 commit comments

Comments
 (0)
0