Skip to content

[TwigBridge] do not render the same label id attribute twice #42049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<{{ element|default('div') }} class="custom-file">
{%- set type = type|default('file') -%}
{{- block('form_widget_simple') -}}
{%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim }) -%}
{%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim })|filter((value, key) => key != 'id') -%}
<label for="{{ form.vars.id }}" {% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
{%- if attr.placeholder is defined and attr.placeholder is not none -%}
{{- translation_domain is same as(false) ? attr.placeholder : attr.placeholder|trans({}, translation_domain) -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,24 @@ public function testFile()
);
}

public function testFileLabelIdNotDuplicated()
{
$form = $this->factory->createNamed('name', FileType::class);

$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'n/a', 'attr' => ['class' => 'my&class form-control-file'], 'label_attr' => ['id' => 'label-id']],
'/div
[@class="custom-file"]
[
./input
[@type="file"]
[@name="name"]
/following-sibling::label
[@for="name"][not(@id)]
]
'
);
}

public function testFileWithPlaceholder()
{
$form = $this->factory->createNamed('name', FileType::class);
Expand Down