Permalink
Browse files

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

…the 'single_control' option
  • Loading branch information...
1 parent d3bb4d0 commit 246c8852c883fa7e1c3e801e8a05fa4ddddbc5d0 @webmozart webmozart committed Apr 27, 2012
@@ -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(),
@@ -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;
}
/**
@@ -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());
+ }
}
@@ -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'));

0 comments on commit 246c885

Please sign in to comment.