[Form] Remove extra .form-group wrapper around file widget in bootstrap 4

This is a follow-up to https://github.com/symfony/symfony/pull/27958 and
https://github.com/symfony/symfony/pull/27919.

It fixes an extra space between the help text of a FileType widget and the
widget itself. The extra space was cause by a .form-group wrapper in the
file_widget block.
This commit is contained in:
Mickael GOETZ 2018-08-02 13:27:22 +02:00
parent f68cb81316
commit 01e7fe4fb0
2 changed files with 21 additions and 31 deletions

View File

@ -115,17 +115,15 @@
{%- endblock percent_widget %} {%- endblock percent_widget %}
{% block file_widget -%} {% block file_widget -%}
<div class="form-group"> <{{ element|default('div') }} class="custom-file">
<{{ element|default('div') }} class="custom-file"> {%- set type = type|default('file') -%}
{%- set type = type|default('file') -%} {{- block('form_widget_simple') -}}
{{- block('form_widget_simple') -}} <label for="{{ form.vars.id }}" class="custom-file-label">
<label for="{{ form.vars.id }}" class="custom-file-label"> {%- if attr.placeholder is defined -%}
{%- if attr.placeholder is defined -%} {{- translation_domain is same as(false) ? attr.placeholder : attr.placeholder|trans({}, translation_domain) -}}
{{- translation_domain is same as(false) ? attr.placeholder : attr.placeholder|trans({}, translation_domain) -}} {%- endif -%}
{%- endif -%} </label>
</label> </{{ element|default('div') }}>
</{{ element|default('div') }}>
</div>
{% endblock %} {% endblock %}
{% block form_widget_simple -%} {% block form_widget_simple -%}

View File

@ -942,17 +942,13 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'n/a', 'attr' => array('class' => 'my&class form-control-file')), $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'n/a', 'attr' => array('class' => 'my&class form-control-file')),
'/div '/div
[@class="form-group"] [@class="custom-file"]
[ [
./div ./input
[@class="custom-file"] [@type="file"]
[ [@name="name"]
./input /following-sibling::label
[@type="file"] [@for="name"]
[@name="name"]
/following-sibling::label
[@for="name"]
]
] ]
' '
); );
@ -964,17 +960,13 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'n/a', 'attr' => array('class' => 'my&class form-control-file', 'placeholder' => 'Custom Placeholder')), $this->assertWidgetMatchesXpath($form->createView(), array('id' => 'n/a', 'attr' => array('class' => 'my&class form-control-file', 'placeholder' => 'Custom Placeholder')),
'/div '/div
[@class="form-group"] [@class="custom-file"]
[ [
./div ./input
[@class="custom-file"] [@type="file"]
[ [@name="name"]
./input /following-sibling::label
[@type="file"] [@for="name" and text() = "[trans]Custom Placeholder[/trans]"]
[@name="name"]
/following-sibling::label
[@for="name" and text() = "[trans]Custom Placeholder[/trans]"]
]
] ]
' '
); );