Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Form] Fixed: Default value of 'error_bubbling' is now determined by …

…the 'single_control' option
  • Loading branch information...
commit 246c8852c883fa7e1c3e801e8a05fa4ddddbc5d0 1 parent d3bb4d0
@webmozart webmozart authored
View
8 src/Symfony/Component/Form/Extension/Core/Type/FormType.php
@@ -193,6 +193,12 @@ public function getDefaultOptions()
};
};
+ // For any form that is not represented by a single HTML control,
+ // errors should bubble up by default
+ $errorBubbling = function (Options $options) {
+ return !$options['single_control'];
+ };
+
return array(
'data' => null,
'data_class' => $dataClass,
@@ -205,7 +211,7 @@ public function getDefaultOptions()
'pattern' => null,
'property_path' => null,
'by_reference' => true,
- 'error_bubbling' => false,
+ 'error_bubbling' => $errorBubbling,
'error_mapping' => array(),
'label' => null,
'attr' => array(),
View
7 src/Symfony/Component/Form/Form.php
@@ -225,10 +225,7 @@ public function __construct($name, EventDispatcherInterface $dispatcher,
$this->validators = $validators;
$this->required = (Boolean) $required;
$this->disabled = (Boolean) $disabled;
- // NULL is the default meaning:
- // bubble up if the form has children (complex forms)
- // don't bubble up if the form has no children (primitive fields)
- $this->errorBubbling = null === $errorBubbling ? null : (Boolean) $errorBubbling;
+ $this->errorBubbling = (Boolean) $errorBubbling;
$this->emptyData = $emptyData;
$this->attributes = $attributes;
@@ -665,7 +662,7 @@ public function addError(FormError $error)
*/
public function getErrorBubbling()
{
- return null === $this->errorBubbling ? $this->hasChildren() : $this->errorBubbling;
+ return $this->errorBubbling;
}
/**
View
28 src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
@@ -568,4 +568,32 @@ public function testCreateViewDoNoMarkItAsRendered()
$this->assertFalse($view->isRendered());
}
+
+ public function testErrorBubblingIfNoSingleControl()
+ {
+ $form = $this->factory->create('form', null, array(
+ 'single_control' => false,
+ ));
+
+ $this->assertTrue($form->getErrorBubbling());
+ }
+
+ public function testNoErrorBubblingIfSingleControl()
+ {
+ $form = $this->factory->create('form', null, array(
+ 'single_control' => true,
+ ));
+
+ $this->assertFalse($form->getErrorBubbling());
+ }
+
+ public function testOverrideErrorBubbling()
+ {
+ $form = $this->factory->create('form', null, array(
+ 'single_control' => true,
+ 'error_bubbling' => true,
+ ));
+
+ $this->assertTrue($form->getErrorBubbling());
+ }
}
View
55 src/Symfony/Component/Form/Tests/FormTest.php
@@ -133,61 +133,6 @@ public function testDataIsInitializedEmpty()
$this->assertSame('bar', $form->getClientData());
}
- public function testErrorsBubbleUpIfEnabled()
- {
- $error = new FormError('Error!');
- $parent = $this->form;
- $form = $this->getBuilder()->setErrorBubbling(true)->getForm();
-
- $form->setParent($parent);
- $form->addError($error);
-
- $this->assertEquals(array(), $form->getErrors());
- $this->assertEquals(array($error), $parent->getErrors());
- }
-
- public function testErrorsDontBubbleUpIfDisabled()
- {
- $error = new FormError('Error!');
- $parent = $this->form;
- $form = $this->getBuilder()->setErrorBubbling(false)->getForm();
-
- $form->setParent($parent);
- $form->addError($error);
-
- $this->assertEquals(array($error), $form->getErrors());
- $this->assertEquals(array(), $parent->getErrors());
- }
-
- public function testErrorsBubbleUpIfNullAndChildren()
- {
- $error = new FormError('Error!');
- $parent = $this->form;
- $form = $this->getBuilder()
- ->setErrorBubbling(null)
- ->add($this->getBuilder('child'))
- ->getForm();
-
- $form->setParent($parent);
- $form->addError($error);
-
- $this->assertEquals(array(), $form->getErrors());
- $this->assertEquals(array($error), $parent->getErrors());
- }
-
- public function testErrorsDontBubbleUpIfNullAndNoChildren()
- {
- $error = new FormError('Error!');
- $parent = $this->form;
- $form = $this->getBuilder()->setErrorBubbling(null)->getForm();
-
- $form->setParent($parent);
- $form->addError($error);
-
- $this->assertEquals(array($error), $form->getErrors());
- $this->assertEquals(array(), $parent->getErrors());
- }
-
public function testValidIfAllChildrenAreValid()
{
$this->form->add($this->getValidForm('firstName'));
Please sign in to comment.
Something went wrong with that request. Please try again.