Skip to content

Commit

Permalink
[Form] fix #15544 when a collection type attribute "required" is fals…
Browse files Browse the repository at this point in the history
…e, "prototype" should too
  • Loading branch information
HeahDude authored and fabpot committed Dec 18, 2015
1 parent 423f83f commit b4b5d63
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Expand Up @@ -28,6 +28,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['allow_add'] && $options['prototype']) {
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
'required' => $options['required'],
'label' => $options['prototype_name'].'label__',
), $options['options']));
$builder->setAttribute('prototype', $prototype->getForm());
Expand Down
Expand Up @@ -195,4 +195,30 @@ public function testPrototypeDefaultLabel()

$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');
}
}

0 comments on commit b4b5d63

Please sign in to comment.