Be sure that both fields have same value for required option in RepeatedType

This commit is contained in:
stloyd 2011-06-29 18:31:14 +02:00 committed by root
parent 0679220b45
commit f8a6a4b1e5
2 changed files with 7 additions and 4 deletions

View File

@ -22,6 +22,10 @@ class RepeatedType extends AbstractType
*/
public function buildForm(FormBuilder $builder, array $options)
{
// Overwrite required option for child fields
$options['first_options']['required'] = $options['options']['required'];
$options['second_options']['required'] = $options['options']['required'];
$builder
->appendClientTransformer(new ValueToDuplicatesTransformer(array(
$options['first_name'],

View File

@ -59,7 +59,7 @@ class RepeatedTypeTest extends TypeTestCase
$this->assertEquals('Test', $form['first']->getAttribute('label'));
$this->assertEquals('Test2', $form['second']->getAttribute('label'));
$this->assertFalse($form['first']->isRequired());
$this->assertTrue($form['first']->isRequired());
$this->assertTrue($form['second']->isRequired());
}
@ -67,14 +67,13 @@ class RepeatedTypeTest extends TypeTestCase
{
$form = $this->factory->create('repeated', null, array(
'type' => 'field',
'options' => array('label' => 'Label'),
'first_options' => array('required' => false),
'options' => array('label' => 'Label'),
'second_options' => array('label' => 'Second label')
));
$this->assertEquals('Label', $form['first']->getAttribute('label'));
$this->assertEquals('Second label', $form['second']->getAttribute('label'));
$this->assertFalse($form['first']->isRequired());
$this->assertTrue($form['first']->isRequired());
$this->assertTrue($form['second']->isRequired());
}