8000 [TwigBridge] Set Form ID on form element, prevent duplicate form elem… · symfony/symfony@2e1e273 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e1e273

Browse files
committed
[TwigBridge] Set Form ID on form element, prevent duplicate form element attributes
1 parent 78c6ceb commit 2e1e273

15 files changed

+45
-41
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% use "bootstrap_3_layout.html.twig" %}
22

33
{% block form_start -%}
4-
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-horizontal')|trim}) %}
4+
{% set row_attr = row_attr|merge({class: (row_attr.class|default('') ~ ' form-horizontal')|trim}) %}
55
{{- parent() -}}
66
{%- endblock form_start %}
77

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404
{%- else -%}
405405
{% set form_method = "POST" %} F438
406406
{%- endif -%}
407-
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
407+
<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 %}>
408408
{%- if form_method != method -%}
409409
<input type="hidden" name="_method" value="{{ method }}" />
410410
{%- endif -%}

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

Lines 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">', $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">', $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" 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()
@@ -182,7 +182,7 @@ public function testStartTagWithExtraAttributes()
182182
]);
183183

184184
$html = $this->renderStart($form->createView(), [
185-
'attr' => ['class' => 'foobar'],
185+
'row_attr' => ['class' => 'foobar'],
186186
]);
187187

188188
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar form-horizontal">', $html);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function testStartTag()
193193

194194
$html = $this->renderStart($form->createView());
195195

196-
$this->assertSame('<form name="form" method="get" action="http://example.com/directory">', $html);
196+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" id="form_form">', $html);
197197
}
198198

199199
public function testStartTagWithOverriddenVars()
@@ -208,7 +208,7 @@ public function testStartTagWithOverriddenVars()
208208
'action' => 'http://foo.com/directory',
209209
]);
210210

211-
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory">', $html);
211+
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory" id="form_form">', $html);
212212
}
213213

214214
public function testStartTagForMultipartForm()
@@ -222,7 +222,7 @@ public function testStartTagForMultipartForm()
222222

223223
$html = $this->renderStart($form->createView());
224224

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

228228
public function testStartTagWithExtraAttributes()
@@ -233,7 +233,7 @@ public function testStartTagWithExtraAttributes()
233233
]);
234234

235235
$html = $this->renderStart($form->createView(), [
236-
'attr' => ['class' => 'foobar'],
236+
'row_attr' => ['class' => 'foobar'],
237237
]);
238238

239239
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar">', $html);

src/Symfony/Bridge/Twig/Tests/Extension/AbstractDivLayoutTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public function testForm()
414414
]
415415
[@method="post"]
416416
[@action="http://example.com"]
417-
[@class="my&class"]
417+
[@id="form_name"]
418418
'
419419
);
420420
}

src/Symfony/Bridge/Twig/Tests/Extension/AbstractLayoutTestCase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ public function testStartTag()
23742374

23752375
$html = $this->renderStart($form->createView());
23762376

2377-
$this->assertSame('<form name="form" method="get" action="http://example.com/directory">', $html);
2377+
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" id="form_form">', $html);
23782378
}
23792379

23802380
public function testStartTagForPutRequest()
@@ -2406,7 +2406,7 @@ public function testStartTagWithOverriddenVars()
24062406
'action' => 'http://foo.com/directory',
24072407
]);
24082408

2409-
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory">', $html);
2409+
$this->assertSame('<form name="form" method="post" action="http://foo.com/directory" id="form_form">', $html);
24102410
}
24112411

24122412
public function testStartTagForMultipartForm()
@@ -2420,7 +2420,7 @@ public function testStartTagForMultipartForm()
24202420

24212421
$html = $this->renderStart($form->createView());
24222422

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

24262426
public function testStartTagWithExtraAttributes()
@@ -2431,7 +2431,7 @@ public function testStartTagWithExtraAttributes()
24312431
]);
24322432

24332433
$html = $this->renderStart($form->createView(), [
2434-
'attr' => ['class' => 'foobar'],
2434+
'row_attr' => ['class' => 'foobar'],
24352435
]);
24362436

24372437
$this->assertSame('<form name="form" method="get" action="http://example.com/directory" class="foobar">', $html);

src/Symfony/Bridge/Twig/Tests/Extension/AbstractTableLayoutTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public function testForm()
271271
]
272272
[@method="post"]
273273
[@action="http://example.com"]
274-
[@class="my&class"]
274+
[@id="form_name"]
275275
'
276276
);
277277
}

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
3131

3232
$html = $this->renderStart($form->createView());
3333

34-
$this->assertSame('<form name="form" method="get">', $html);
34+
$this->assertSame('<form name="form" method="get" id="form_form">', $html);
3535
}
3636

3737
public function testStartTagHasActionAttributeWhenActionIsZero()
@@ -43,7 +43,7 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
4343

4444
$html = $this->renderStart($form->createView());
4545

46-
$this->assertSame('<form name="form" method="get" action="0">', $html);
46+
$this->assertSame('<form name="form" method="get" action="0" id="form_form">', $html);
4747
}
4848

4949
public function testMoneyWidgetInIso()

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap4LayoutTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
3636

3737
$html = $this->renderStart($form->createView());
3838

39-
$this->assertSame('<form name="form" method="get">', $html);
39+
$this->assertSame('<form name="form" method="get" id="form_form">', $html);
4040
}
4141

4242
public function testStartTagHasActionAttributeWhenActionIsZero()
@@ -48,7 +48,7 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
4848

4949
$html = $this->renderStart($form->createView());
5050

51-
$this->assertSame('<form name="form" method="get" action="0">', $html);
51+
$this->assertSame('<form name="form" method="get" action="0" id="form_form">', $html);
5252
}
5353

5454
public function testMoneyWidgetInIso()

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap5LayoutTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testStartTagHasNoActionAttributeWhenActionIsEmpty()
3838

3939
$html = $this->renderStart($form->createView());
4040

41-
self::assertSame('<form name="form" method="get">', $html);
41+
self::assertSame('<form name="form" method="get" id="form_form">', $html);
4242
}
4343

4444
public function testStartTagHasActionAttributeWhenActionIsZero()
@@ -50,7 +50,7 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
5050

5151
$html = $this->renderStart($form->createView());
5252

53-
self::assertSame('<form name="form" method="get" action="0">', $html);
53+
self::assertSame('<form name="form" method="get" action="0" id="form_form">', $html);
5454
}
5555

5656
public function testMoneyWidgetInIso()

0 commit comments

Comments
 (0)
0