bug #26591 [TwigBridge] Make sure we always render errors. Eventhough labels are disabled (Nyholm)

This PR was merged into the 3.4 branch.

Discussion
----------

[TwigBridge] Make sure we always render errors. Eventhough labels are disabled

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26536
| License       | MIT
| Doc PR        |

If one use form type with `'label'=>false` then no errors where visible. This PR make sure we always print errors.

Commits
-------

d8f3de91d5 Make sure we always render errors. Eventhough labels are disabled
This commit is contained in:
Fabien Potencier 2018-03-18 20:01:56 +01:00
commit c59bbc554f
2 changed files with 16 additions and 0 deletions

View File

@ -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) -}}</{{ element|default('label') }}>
{%- else -%}
{%- if errors|length > 0 -%}
<div id="{{ id }}_errors" class="mb-2">
{{- form_errors(form) -}}
</div>
{%- endif -%}
{%- endif -%}
{%- endblock form_label %}

View File

@ -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);