From 6efc6b2e00fc72d6a3ff4d10c491719aa020e4bb Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 30 Jun 2016 17:04:01 +0200 Subject: [PATCH] Do not put any empty div if label is disabled This produces wrong alignments especially for form collections. --- .../views/Form/bootstrap_3_horizontal_layout.html.twig | 10 ++++++---- .../Tests/AbstractBootstrap3HorizontalLayoutTest.php | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig index 5de20b1b8f181..6a43d14f8aa57 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_horizontal_layout.html.twig @@ -9,9 +9,7 @@ {% block form_label -%} {% spaceless %} - {% if label is same as(false) %} -
- {% else %} + {% if label is not same as(false) %} {% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) %} {{- parent() -}} {% endif %} @@ -77,5 +75,9 @@ col-sm-2 {% endblock reset_row %} {% block form_group_class -%} -col-sm-10 + {%- if label is same as(false) -%} + col-sm-12 + {%- else -%} + col-sm-10 + {%- endif -%} {%- endblock form_group_class %} diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php index 0fcfd60e47c1c..80de39045daed 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap3HorizontalLayoutTest.php @@ -100,6 +100,16 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly ); } + public function testLabelNoDivIfFalse() + { + $this->assertEmpty( + $this->renderLabel( + $this->factory->createNamed('name', 'date', null, array('label' => false))->createView() + ), + 'The label should not be rendered' + ); + } + public function testStartTag() { $form = $this->factory->create('form', null, array(