[Form] Fixed: FieldGroup::hasErrors() does not return true if only children have errors
This commit is contained in:
parent
c5ceb37f8b
commit
681ce7f46a
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
|
Reference in New Issue
Block a user