Skip to content
Permalink
Browse files

update hasError() - fix#4563

  • Loading branch information...
antograssiot committed Sep 10, 2014
1 parent cd1c595 commit d87fcbb1ea35541c82ac30463b7ee381e3a65bd7
Showing with 18 additions and 1 deletion.
  1. +10 −1 src/View/Form/EntityContext.php
  2. +8 −0 tests/TestCase/View/Form/EntityContextTest.php
@@ -456,7 +456,16 @@ public function attributes($field) {
* @return bool Returns true if the errors for the field are not empty.
*/
public function hasError($field) {
return $this->error($field) !== [];
$errors = $this->error($field);
if ($errors !== []) {
foreach ($errors as $key => $value) {
if (!is_null($value)) {
return true;
}
}
return false;
}
return false;
}
/**
@@ -794,6 +794,13 @@ public function testHasError() {
'user' => new Entity(['username' => 'Mark']),
]);
$row->errors('title', []);
$row->errors(['uploadedFile' => [
'name' => null,
'tmp_name' => null,
'error' => null,
'type' => null,
'size' => null
]]);
$row->errors('body', 'Gotta have one');
$row->errors('user_id', ['Required field']);
$context = new EntityContext($this->request, [
@@ -802,6 +809,7 @@ public function testHasError() {
]);
$this->assertFalse($context->hasError('title'));
$this->assertFalse($context->hasError('uploadedFile'));
$this->assertFalse($context->hasError('nope'));
$this->assertTrue($context->hasError('body'));
$this->assertTrue($context->hasError('user_id'));

0 comments on commit d87fcbb

Please sign in to comment.
You can’t perform that action at this time.