8000 [Form] Changed checkboxes in an expanded multiple-choice field to not… · symfony/symfony@61d792e · GitHub
[go: up one dir, main page]

Skip to content

Commit 61d792e

Browse files
committed
[Form] Changed checkboxes in an expanded multiple-choice field to not include the choice index
1 parent bc9bc4a commit 61d792e

File tree

5 files changed

+25
-37
lines changed

5 files changed

+25
-37
lines changed

CHANGELOG-2.1.md

Copy file name to clipboard
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
263263
in class Form now throw an exception if the form is already bound
264264
* fields of constrained classes without a NotBlank or NotNull constraint are
265265
set to not required now, as stated in the docs
266+
* checkboxes of in an expanded multiple-choice field don't include the choice
267+
in their name anymore. Their names terminate with "[]" now.
266268

267269
### HttpFoundation
268270

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ public function buildView(FormView $view, FormInterface $form)
143143
}
144144
}
145145

146+
/**
147+
* {@inheritdoc}
148+
*/
149+
public function buildViewBottomUp(FormView $view, FormInterface $form)
150+
{
151+
if ($view->get('expanded')) {
152+
// Radio buttons should have the same name as the parent
153+
$childName = $view->get('full_name');
154+
155+
// Checkboxes should append "[]" to allow multiple selection
156+
if ($view->get('multiple')) {
157+
$childName .= '[]';
158+
}
159+
160+
foreach ($view->getChildren() as $childView) {
161+
$childView->set('full_name', $childName);
162+
}
163+
}
164+
}
165+
146166
/**
147167
* {@inheritdoc}
148168
*/

src/Symfony/Component/Form/Extension/Core/Type/RadioType.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@
1717

1818
class RadioType extends AbstractType
1919
{
20-
/**
21-
* {@inheritdoc}
22-
*/
23-
public function buildView(FormView $view, FormInterface $form)
24-
{
25-
if ($view->hasParent()) {
26-
$view->set('full_name', $view->getParent()->get('full_name'));
27-
}
28-
}
29-
3020
/**
3121
* {@inheritdoc}
3222
*/

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,11 @@ public function testMultipleChoiceExpanded()
711711
$this->assertWidgetMatchesXpath($form->createView(), array(),
712712
'/div
713713
[
714-
./input[@type="checkbox"][@name="name[0]"][@id="name_0"][@checked][not(@required)]
714+
./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
715715
/following-sibling::label[@for="name_0"][.="[trans]Choice&A[/trans]"]
716-
/following-sibling::input[@type="checkbox"][@name="name[1]"][@id="name_1"][not(@checked)][not(@required)]
716+
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
717717
/following-sibling::label[@for="name_1"][.="[trans]Choice&B[/trans]"]
718-
/following-sibling::input[@type="checkbox"][@name="name[2]"][@id="name_2"][@checked][not(@required)]
718+
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
719719
/following-sibling::label[@for="name_2"][.="[trans]Choice&C[/trans]"]
720720
]
721721
[count(./input)=3]

src/Symfony/Component/Form/Tests/Extension/Core/Type/RadioTypeTest.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 com 31E7 mit comments

Comments
 (0)
0