DateIntervalType: 'invert' should not inherit the 'required' option

This commit is contained in:
Luis Galeas 2016-12-12 12:57:13 +00:00 committed by Fabien Potencier
parent 0439abba8e
commit b1597f17c2
2 changed files with 19 additions and 7 deletions

View File

@ -107,9 +107,6 @@ class DateIntervalType extends AbstractType
}
}
}
$invertOptions = array(
'error_bubbling' => true,
);
// Append generic carry-along options
foreach (array('required', 'translation_domain') as $passOpt) {
foreach ($this->timeParts as $part) {
@ -117,9 +114,6 @@ class DateIntervalType extends AbstractType
$childOptions[$part][$passOpt] = $options[$passOpt];
}
}
if ($options['with_invert']) {
$invertOptions[$passOpt] = $options[$passOpt];
}
}
foreach ($this->timeParts as $part) {
if ($options['with_'.$part]) {
@ -135,7 +129,11 @@ class DateIntervalType extends AbstractType
}
}
if ($options['with_invert']) {
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', $invertOptions);
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', array(
'error_bubbling' => true,
'required' => false,
'translation_domain' => $options['translation_domain'],
));
}
$builder->addViewTransformer(new DateIntervalToArrayTransformer($parts, 'text' === $options['widget']));
}

View File

@ -364,4 +364,18 @@ class DateIntervalTypeTest extends TestCase
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
}
public function testInvertDoesNotInheritRequiredOption()
{
$form = $this->factory->create(
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
null,
array(
'input' => 'dateinterval',
'with_invert' => true,
'required' => true,
)
);
$this->assertFalse($form->get('invert')->getConfig()->getOption('required'));
}
}