Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cd2eef

Browse files
author
Jannik Zschiesche
committed
Add placeholder support in bootstrap 4 file fields
1 parent 25df3e3 commit 3cd2eef

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@
119119
<{{ element|default('div') }} class="custom-file">
120120
{%- set type = type|default('file') -%}
121121
{{- block('form_widget_simple') -}}
122-
<label for="{{ form.vars.id }}" class="custom-file-label">Choose File</label>
122+
<label for="{{ form.vars.id }}" class="custom-file-label">
123+
{%- if attr.placeholder is defined -%}
124+
{{- translation_domain is same as(false) ? attr.placeholder : attr.placeholder|trans({}, translation_domain) -}}
125+
{%- endif -%}
126+
</label>
123127
</{{ element|default('div') }}>
124128
</div>
125129
{% endblock %}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ public function testFile()
940940
{
941941
$form = $this->factory->createNamed('name', FileType::class);
942942

943-
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'nope', 'attr' => array('class' => 'my&class form-control-file')),
943+
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'n/a', 'attr' => array('class' => 'my&class form-control-file')),
944944
'/div
945945
[@class="form-group"]
946946
[
@@ -958,6 +958,28 @@ public function testFile()
958958
);
959959
}
960960

961+
public function testFileWithPlaceholder()
962+
{
963+
$form = $this->factory->createNamed('name', FileType::class);
964+
965+
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'n/a', 'attr' => array('class' => 'my&class form-control-file', 'placeholder' => 'Custom Placeholder')),
966+
'/div
967+
[@class="form-group"]
968+
[
969+
./div
970+
[@class="custom-file"]
971+
[
972+
./input
973+
[@type="file"]
974+
[@name="name"]
975+
/following-sibling::label
976+
[@for="name" and text() = "[trans]Custom Placeholder[/trans]"]
977+
]
978+
]
979+
'
980+
);
981+
}
982+
961983
public function testMoney()
962984
{
963985
$form = $this->factory->createNamed('name', MoneyType::class, 1234.56, array(

0 commit comments

Comments
 (0)