[Form] Fixed: Default value of 'error_bubbling' is now determined by the 'single_control' option
This commit is contained in:
parent
d3bb4d085c
commit
246c8852c8
@ -193,6 +193,12 @@ class FormType extends AbstractType
|
||||
};
|
||||
};
|
||||
|
||||
// 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 @@ class FormType extends AbstractType
|
||||
'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 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
$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 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
*/
|
||||
public function getErrorBubbling()
|
||||
{
|
||||
return null === $this->errorBubbling ? $this->hasChildren() : $this->errorBubbling;
|
||||
return $this->errorBubbling;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -568,4 +568,32 @@ class FormTypeTest extends TypeTestCase
|
||||
|
||||
$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 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
$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'));
|
||||
|
Reference in New Issue
Block a user