[Form] Changed checkboxes in an expanded multiple-choice field to not include the choice index
This commit is contained in:
parent
bc9bc4af5d
commit
61d792eebd
@ -263,6 +263,8 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
|
||||
in class Form now throw an exception if the form is already bound
|
||||
* fields of constrained classes without a NotBlank or NotNull constraint are
|
||||
set to not required now, as stated in the docs
|
||||
* checkboxes of in an expanded multiple-choice field don't include the choice
|
||||
in their name anymore. Their names terminate with "[]" now.
|
||||
|
||||
### HttpFoundation
|
||||
|
||||
|
@ -143,6 +143,26 @@ class ChoiceType extends AbstractType
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildViewBottomUp(FormView $view, FormInterface $form)
|
||||
{
|
||||
if ($view->get('expanded')) {
|
||||
// Radio buttons should have the same name as the parent
|
||||
$childName = $view->get('full_name');
|
||||
|
||||
// Checkboxes should append "[]" to allow multiple selection
|
||||
if ($view->get('multiple')) {
|
||||
$childName .= '[]';
|
||||
}
|
||||
|
||||
foreach ($view->getChildren() as $childView) {
|
||||
$childView->set('full_name', $childName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -17,16 +17,6 @@ use Symfony\Component\Form\FormView;
|
||||
|
||||
class RadioType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form)
|
||||
{
|
||||
if ($view->hasParent()) {
|
||||
$view->set('full_name', $view->getParent()->get('full_name'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -711,11 +711,11 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||
'/div
|
||||
[
|
||||
./input[@type="checkbox"][@name="name[0]"][@id="name_0"][@checked][not(@required)]
|
||||
./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
|
||||
/following-sibling::label[@for="name_0"][.="[trans]Choice&A[/trans]"]
|
||||
/following-sibling::input[@type="checkbox"][@name="name[1]"][@id="name_1"][not(@checked)][not(@required)]
|
||||
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
|
||||
/following-sibling::label[@for="name_1"][.="[trans]Choice&B[/trans]"]
|
||||
/following-sibling::input[@type="checkbox"][@name="name[2]"][@id="name_2"][@checked][not(@required)]
|
||||
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
|
||||
/following-sibling::label[@for="name_2"][.="[trans]Choice&C[/trans]"]
|
||||
]
|
||||
[count(./input)=3]
|
||||
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
class RadioTypeTest extends TypeTestCase
|
||||
{
|
||||
public function testPassParentFullNameToView()
|
||||
{
|
||||
$parent = $this->factory->createNamed('field', 'parent');
|
||||
$parent->add($this->factory->createNamed('radio', 'child'));
|
||||
$view = $parent->createView();
|
||||
|
||||
$this->assertEquals('parent', $view['child']->get('full_name'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user