[Form] Fixed: FieldGroup::hasErrors() does not return true if only children have errors

This commit is contained in:
Bernhard Schussek 2010-11-16 19:54:26 +01:00 committed by Fabien Potencier
parent c5ceb37f8b
commit 681ce7f46a
2 changed files with 15 additions and 1 deletions

View File

@ -349,7 +349,11 @@ abstract class Field extends Configurable implements FieldInterface
*/
public function hasErrors()
{
return $this->isBound() && !$this->isValid();
// Don't call isValid() here, as its semantics are slightly different
// Field groups are not valid if their children are invalid, but
// hasErrors() returns only true if a field/field group itself has
// errors
return count($this->errors) > 0;
}
/**

View File

@ -119,6 +119,16 @@ class FieldGroupTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($group->isBoundWithExtraFields());
}
public function testHasNoErrorsIfOnlyFieldHasErrors()
{
$group = new TestFieldGroup('author');
$group->add($this->createInvalidMockField('firstName'));
$group->bind(array('firstName' => 'Bernhard'));
$this->assertFalse($group->hasErrors());
}
public function testBindForwardsBoundValues()
{
$field = $this->createMockField('firstName');