8000 DateIntervalType: 'invert' should not inherit the 'required' option · symfony/symfony@b1597f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1597f1

Browse files
galeaspablofabpot
authored andcommitted
DateIntervalType: 'invert' should not inherit the 'required' option
1 parent 0439abb commit b1597f1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
107107
}
108108
}
109109
}
110-
$invertOptions = array(
111-
'error_bubbling' => true,
112-
);
113110
// Append generic carry-along options
114111
foreach (array('required', 'translation_domain') as $passOpt) {
115112
foreach ($this->timeParts as $part) {
116113
if ($options['with_'.$part]) {
117114
$childOptions[$part][$passOpt] = $options[$passOpt];
118115
}
119116
}
120-
if ($options['with_invert']) {
121-
$invertOptions[$passOpt] = $options[$passOpt];
122-
}
123117
}
124118
foreach ($this->timeParts as $part) {
125119
if ($options['with_'.$part]) {
@@ -135,7 +129,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
135129
}
136130
}
137131
if ($options['with_invert']) {
138-
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', $invertOptions);
132+
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', array(
133+
'error_bubbling' => true,
134+
'required' => false,
135+
'translation_domain' => $options['translation_domain'],
136+
));
139137
}
140138
$builder->addViewTransformer(new DateIntervalToArrayTransformer($parts, 'text' === $options['widget']));
141139
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateIntervalTypeTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,18 @@ public function testDateTypeChoiceErrorsBubbleUp()
364364
$this->assertSame(array(), iterator_to_array($form['years']->getErrors()));
365365
$this->assertSame(array($error), iterator_to_array($form->getErrors()));
366366
}
367+
368+
public function testInvertDoesNotInheritRequiredOption()
369+
{
370+
$form = $this->factory->create(
371+
'Symfony\Component\Form\Extension\Core\Type\DateIntervalType',
372+
null,
373+
array(
374+
'input' => 'dateinterval',
375+
'with_invert' => true,
376+
'required' => true,
377+
)
378+
);
379+
$this->assertFalse($form->get('invert')->getConfig()->getOption('required'));
380+
}
367381
}

0 commit comments

Comments
 (0)
0