8000 bug #27958 [Form] Remaining changes for bootstrap 4 file fields (apfe… · nicolas-grekas/symfony@87f5e4f · GitHub
[go: up one dir, main page]

Skip to content

Commit 87f5e4f

Browse files
fabpotnicolas-grekas
authored andcommitted
bug symfony#27958 [Form] Remaining changes for bootstrap 4 file fields (apfelbox)
This PR was merged into the 4.1 branch. Discussion ---------- [Form] Remaining changes for bootstrap 4 file fields | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | — | License | MIT | Doc PR | — Hi again, This is a follow-up PR for symfony#27919 Apparently I talked about it in the previous PR, but forgot to actually push the change. Sorry about that! 😞 This PR no actually adds this instead of just talking about it: ![2018-07-15 at 17 52](https://user-images.githubusercontent.com/1032411/42735630-e19b22be-8857-11e8-85b8-6d64e17c2be2.png) Sorry again, just forgot to actually update the last PR. Commits ------- 3cd2eef Add placeholder support in bootstrap 4 file fields
1 parent 929701a commit 87f5e4f

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
@@ -923,7 +923,7 @@ public function testFile()
923923
{
924924
$form = $this->factory->createNamed('name', FileType::class);
925925

926-
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'nope', 'attr' => array('class' => 'my&class form-control-file')),
926+
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'n/a', 'attr' => array('class' => 'my&class form-control-file')),
927927
'/div
928928
[@class="form-group"]
929929
[
@@ -941,6 +941,28 @@ public function testFile()
941941
);
942942
}
943943

944+
public function testFileWithPlaceholder()
945+
{
946+
$form = $this->factory->createNamed('name', FileType::class);
947+
948+
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'n/a', 'attr' => array('class' => 'my&class form-control-file', 'placeholder' => 'Custom Placeholder')),
949+
'/div
950+
[@class="form-group"]
951+
[
952+
./div
953+
[@class="custom-file"]
954+
[
955+
./input
956+
[@type="file"]
957+
[@name="name"]
958+
/following-sibling::label
959+
[@for="name" and text() = "[trans]Custom Placeholder[/trans]"]
960+
]
961+
]
962+
'
963+
);
964+
}
965+
944966
public function testMoney()
945967
{
946968
$form = $this->factory->createNamed('name', MoneyType::class, 1234.56, array(

0 commit comments

Comments
 (0)
0