8000 DateIntervalType: 'invert' should not inherit the 'required' option by galeaspablo · Pull Request #20877 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
8000
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
DateIntervalType: 'invert' should not inherit the 'required' option
  • Loading branch information
galeaspablo committed Dec 12, 2016
commit 63761d96c1d36bfca8131e18c98d262ab26636f3
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add($childForm);
}
}
// Invert should not inherit the required option
$invertOptions['required'] = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8000

What about

diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
index fb2b7d7..e4f46d8 100644
--- a/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
+++ b/src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php
@@ -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,10 +114,8 @@ 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]) {
                     $childForm = $builder->create($part, self::$widgets[$options['widget']], $childOptions[$part]);
@@ -135,7 +130,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']));
         }

instead? Not much different, but simplify things a little bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Changed. 👍

if ($options['with_invert']) {
$builder->add('invert', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', $invertOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,18 @@ public function testDateTypeChoiceErrorsBubbleUp()
$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'));
}
}
0