Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8dd761e

Browse filesBrowse files
committed
Fix ID on form element
1 parent 624a4e3 commit 8dd761e
Copy full SHA for 8dd761e

File tree

7 files changed

+25
-22
lines changed
Filter options

7 files changed

+25
-22
lines changed

‎src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@
392392
{%- else -%}
393393
{% set form_method = "POST" %}
394394
{%- endif -%}
395-
{%- set row_attr = row_attr|merge({id: form_id}) -%}
396395
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{% with { attr: row_attr} %}{{ block('attributes') }}{% endwith %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
397396
{%- if form_method != method -%}
398397
<input type="hidden" name="_method" value="{{ method }}" />

‎src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3HorizontalLayoutTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3HorizontalLayoutTestCase.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testStartTag()
142142

143143
$html = $this->renderStart($form->createView());
144144

145-
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal" id="form_form">', $html);
145+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" id="form_form" class="form-horizontal">', $html);
146146
}
147147

148148
public function testStartTagWithOverriddenVars()
@@ -157,7 +157,7 @@ public function testStartTagWithOverriddenVars()
157157
'action' => 'http://foo.com/directory',
158158
]);
159159

160-
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory" class="form-horizontal" id="form_form">', $html);
160+
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory" id="form_form" class="form-horizontal">', $html);
161161
}
162162

163163
public function testStartTagForMultipartForm()
@@ -171,7 +171,7 @@ public function testStartTagForMultipartForm()
171171

172172
$html = $this->renderStart($form->createView());
173173

174-
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="form-horizontal" id="form_form" enctype="multipart/form-data">', $html);
174+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" id="form_form" class="form-horizontal" enctype="multipart/form-data">', $html);
175175
}
176176

177177
public function testStartTagWithExtraAttributes()
@@ -185,7 +185,7 @@ public function testStartTagWithExtraAttributes()
185185
'row_attr' => ['class' => 'foobar'],
186186
]);
187187

188-
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar form-horizontal" id="form_form">', $html);
188+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar form-horizontal">', $html);
189189
}
190190

191191
public function testCheckboxRow()

‎src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4HorizontalLayoutTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4HorizontalLayoutTestCase.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function testStartTagWithExtraAttributes()
236236
'row_attr' => ['class' => 'foobar'],
237237
]);
238238

239-
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar" id="form_form">', $html);
239+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar">', $html);
240240
}
241241

242242
public function testCheckboxRow()

‎src/Symfony/Component/Form/Extension/Core/Type/BaseType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/BaseType.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,25 @@ public function buildView(FormView $view, FormInterface $form, array $options)
7373
}
7474

7575
$rootFormAttrOption = $form->getRoot()->getConfig()->getOption('form_attr');
76+
$rootFormName = $form->getRoot()->getName();
7677
if ($options['form_attr'] || $rootFormAttrOption) {
77-
$options['attr']['form'] = \is_string($rootFormAttrOption) ? $rootFormAttrOption : $form->getRoot()->getName();
78-
if (empty($options['attr']['form'])) {
78+
if (true === $rootFormAttrOption && empty($rootFormName)) {
7979
throw new LogicException('"form_attr" option must be a string identifier on root form when it has no id.');
8080
}
81+
82+
$options['attr']['form'] = \is_string($rootFormAttrOption) ? $rootFormAttrOption : 'form_'.$rootFormName;
8183
}
8284
} else {
83-
$id = \is_string($options['form_attr']) ? $options['form_attr'] : $name;
85+
$id = $name;
8486
$fullName = $name;
8587
$uniqueBlockPrefix = '_'.$blockName;
8688

8789
// Strip leading underscores and digits. These are allowed in
8890
// form names, but not in HTML4 ID attributes.
8991
// https://www.w3.org/TR/html401/struct/global#adef-id
9092
$id = ltrim($id, '_0123456789');
93+
94+
$options['row_attr'] += ['id' => \is_string($options['form_attr']) ? $options['form_attr'] : 'form_'.$id];
9195
}
9296

9397
$blockPrefixes = [];

‎src/Symfony/Component/Form/Tests/AbstractLayoutTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/AbstractLayoutTestCase.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,7 @@ public function testStartTagWithExtraAttributes()
24842484
'row_attr' => ['class' => 'foobar'],
24852485
]);
24862486

2487-
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar" id="form_form">', $html);
2487+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar">', $html);
24882488
}
24892489

24902490
public function testWidgetAttributes()

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/ButtonTypeTest.php
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function testFormAttrOnRoot()
5050
->getForm()
5151
->createView();
5252
$this->assertArrayNotHasKey('form', $view->vars['attr']);
53-
$this->assertSame($view->vars['id'], $view['child1']->vars['attr']['form']);
54-
$this->assertSame($view->vars['id'], $view['child2']->vars['attr']['form']);
53+
$this->assertSame($view->vars['row_attr']['id'], $view['child1']->vars['attr']['form']);
54+
$this->assertSame($view->vars['row_attr']['id'], $view['child2']->vars['attr']['form']);
5555
}
5656

5757
public function testFormAttrOnChild()
@@ -65,7 +65,7 @@ public function testFormAttrOnChild()
6565
->getForm()
6666
->createView();
6767
$this->assertArrayNotHasKey('form', $view->vars['attr']);
68-
$this->assertSame($view->vars['id'], $view['child1']->vars['attr']['form']);
68+
$this->assertSame($view->vars['row_attr']['id'], $view['child1']->vars['attr']['form']);
6969
$this->assertArrayNotHasKey('form', $view['child2']->vars['attr']);
7070
}
7171

@@ -95,8 +95,8 @@ public function testFormAttrAsStringWithNoId()
9595
->getForm()
9696
->createView();
9797
$this->assertArrayNotHasKey('form', $view->vars['attr']);
98-
$this->assertSame($stringId, $view->vars['id']);
99-
$this->assertSame($view->vars['id'], $view['child1']->vars['attr']['form']);
100-
$this->assertSame($view->vars['id'], $view['child2']->vars['attr']['form']);
98+
$this->assertSame($stringId, $view->vars['row_attr']['id']);
99+
$this->assertSame($view->vars['row_attr']['id'], $view['child1']->vars['attr']['form']);
100+
$this->assertSame($view->vars['row_attr']['id'], $view['child2']->vars['attr']['form']);
101101
}
102102
}

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ public function testFormAttrOnRoot()
787787
->getForm()
788788
->createView();
789789
$this->assertArrayNotHasKey('form', $view->vars['attr']);
790-
$this->assertSame($view->vars['form_id'], $view['child1']->vars['attr']['form']);
791-
$this->assertSame($view->vars['form_id'], $view['child2']->vars['attr']['form']);
790+
$this->assertSame($view->vars['row_attr']['id'], $view['child1']->vars['attr']['form']);
791+
$this->assertSame($view->vars['row_attr']['id'], $view['child2']->vars['attr']['form']);
792792
}
793793

794794
public function testFormAttrOnChild()
@@ -802,7 +802,7 @@ public function testFormAttrOnChild()
802802
->getForm()
803803
->createView();
804804
$this->assertArrayNotHasKey('form', $view->vars['attr']);
805-
$this->assertSame($view->vars['form_id'], $view['child1']->vars['attr']['form']);
805+
$this->assertSame($view->vars['row_attr']['id'], $view['child1']->vars['attr']['form']);
806806
$this->assertArrayNotHasKey('form', $view['child2']->vars['attr']);
807807
}
808808

@@ -832,9 +832,9 @@ public function testFormAttrAsStringWithNoId()
832832
->getForm()
833833
->createView();
834834
$this->assertArrayNotHasKey('form', $view->vars['attr']);
835-
$this->assertSame($stringId, $view->vars['id']);
836-
$this->assertSame($view->vars['id'], $view['child1']->vars['attr']['form']);
837-
$this->assertSame($view->vars['id'], $view['child2']->vars['attr']['form']);
835+
$this->assertSame($stringId, $view->vars['row_attr']['id']);
836+
$this->assertSame($view->vars['row_attr']['id'], $view['child1']->vars['attr']['form']);
837+
$this->assertSame($view->vars['row_attr']['id'], $view['child2']->vars['attr']['form']);
838838
}
839839

840840
public function testSortingViewChildrenBasedOnPriorityOption()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.