Skip to content

Commit 667a6e5

Browse files
committed
do not render the same label id attribute twice
1 parent 9d02487 commit 667a6e5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
<{{ element|default('div') }} class="custom-file">
123123
{%- set type = type|default('file') -%}
124124
{{- block('form_widget_simple') -}}
125-
{%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim }) -%}
125+
{%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim })|filter((value, key) => key != 'id') -%}
126126
<label for="{{ form.vars.id }}" {% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
127127
{%- if attr.placeholder is defined and attr.placeholder is not none -%}
128128
{{- translation_domain is same as(false) ? attr.placeholder : attr.placeholder|trans({}, translation_domain) -}}

Tests/Extension/AbstractBootstrap4LayoutTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,24 @@ public function testFile()
10881088
);
10891089
}
10901090

1091+
public function testFileLabelIdNotDuplicated()
1092+
{
1093+
$form = $this->factory->createNamed('name', FileType::class);
1094+
1095+
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'n/a', 'attr' => ['class' => 'my&class form-control-file'], 'label_attr' => ['id' => 'label-id']],
1096+
'/div
1097+
[@class="custom-file"]
1098+
[
1099+
./input
1100+
[@type="file"]
1101+
[@name="name"]
1102+
/following-sibling::label
1103+
[@for="name"][not(@id)]
1104+
]
1105+
'
1106+
);
1107+
}
1108+
10911109
public function testFileWithPlaceholder()
10921110
{
10931111
$form = $this->factory->createNamed('name', FileType::class);

0 commit comments

Comments
 (0)