[Form] fix #15544 when a collection type attribute "required" is false, "prototype" should too
This commit is contained in:
parent
423f83f75e
commit
b4b5d63660
@ -28,6 +28,7 @@ class CollectionType extends AbstractType
|
|||||||
{
|
{
|
||||||
if ($options['allow_add'] && $options['prototype']) {
|
if ($options['allow_add'] && $options['prototype']) {
|
||||||
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
|
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
|
||||||
|
'required' => $options['required'],
|
||||||
'label' => $options['prototype_name'].'label__',
|
'label' => $options['prototype_name'].'label__',
|
||||||
), $options['options']));
|
), $options['options']));
|
||||||
$builder->setAttribute('prototype', $prototype->getForm());
|
$builder->setAttribute('prototype', $prototype->getForm());
|
||||||
|
@ -195,4 +195,30 @@ class CollectionTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
|||||||
|
|
||||||
$this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']);
|
$this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPrototypeDefaultRequired()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('collection', array(), array(
|
||||||
|
'type' => 'file',
|
||||||
|
'allow_add' => true,
|
||||||
|
'prototype' => true,
|
||||||
|
'prototype_name' => '__test__',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertTrue($form->createView()->vars['prototype']->vars['required']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPrototypeSetNotRequired()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create('collection', array(), array(
|
||||||
|
'type' => 'file',
|
||||||
|
'allow_add' => true,
|
||||||
|
'prototype' => true,
|
||||||
|
'prototype_name' => '__test__',
|
||||||
|
'required' => false,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertFalse($form->createView()->vars['required'], 'collection is not required');
|
||||||
|
$this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user