[Form] fixed isValid() on readOnly forms that have children
This commit is contained in:
parent
44816ebca0
commit
8d55df42de
@ -679,10 +679,12 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->children as $child) {
|
||||
if (!$child->isValid()) {
|
||||
if (!$this->readOnly) {
|
||||
foreach ($this->children as $child) {
|
||||
if (!$child->isValid()) {
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,6 +306,22 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($form->isValid());
|
||||
}
|
||||
|
||||
public function testValidIfBoundAndReadOnlyWithChildren()
|
||||
{
|
||||
$this->factory->expects($this->once())
|
||||
->method('createNamedBuilder')
|
||||
->with('text', 'name', null, array())
|
||||
->will($this->returnValue($this->getBuilder('name')));
|
||||
|
||||
$form = $this->getBuilder('person')
|
||||
->setReadOnly(true)
|
||||
->add('name', 'text')
|
||||
->getForm();
|
||||
$form->bind(array('name' => 'Jacques Doe'));
|
||||
|
||||
$this->assertTrue($form->isValid());
|
||||
}
|
||||
|
||||
public function testNotValidIfNotBound()
|
||||
{
|
||||
$this->assertFalse($this->form->isValid());
|
||||
|
Reference in New Issue
Block a user