diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 41cf2c1e9..f1002c661 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -1434,6 +1434,31 @@ class FormHelperTest extends CakeTestCase { $this->assertEquals(array(), $this->Form->fields); } +/** + * testTagIsInvalid method + * + * @return void + */ + public function testTagIsInvalid() { + $Contact = ClassRegistry::getObject('Contact'); + $Contact->validationErrors[0]['email'] = array('Please provide an email'); + + $this->Form->setEntity('Contact.0.email'); + $result = $this->Form->tagIsInvalid(); + $expected = array('Please provide an email'); + $this->assertEquals($expected, $result); + + $this->Form->setEntity('Contact.1.email'); + $result = $this->Form->tagIsInvalid(); + $expected = false; + $this->assertIdentical($expected, $result); + + $this->Form->setEntity('Contact.0.name'); + $result = $this->Form->tagIsInvalid(); + $expected = false; + $this->assertIdentical($expected, $result); + } + /** * testPasswordValidation method * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 80dca5840..ea354d3d1 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -272,8 +272,8 @@ class FormHelper extends AppHelper { * Returns false if given form field described by the current entity has no errors. * Otherwise it returns the validation message * - * @return mixed Either false when there or no errors, or the error - * string. The error string could be ''. + * @return mixed Either false when there or no errors, or an array of error + * strings. An error string could be ''. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::tagIsInvalid */ public function tagIsInvalid() { @@ -289,8 +289,8 @@ class FormHelper extends AppHelper { if (empty($errors)) { return false; } - $error = Set::classicExtract($errors, join('.', $entity)); - return $error === null ? false : $error; + $errors = Set::classicExtract($errors, join('.', $entity)); + return $errors === null ? false : $errors; } /** @@ -739,7 +739,7 @@ class FormHelper extends AppHelper { * * ### Options * - * - `for` - Set the for attribute, if its not defined the for attribute + * - `for` - Set the for attribute, if its not defined the for attribute * will be generated from the $fieldName parameter using * FormHelper::domId(). * @@ -776,8 +776,8 @@ class FormHelper extends AppHelper { * }}} * * @param string $fieldName This should be "Modelname.fieldname" - * @param string $text Text that will appear in the label field. If - * $text is left undefined the text will be inflected from the + * @param string $text Text that will appear in the label field. If + * $text is left undefined the text will be inflected from the * fieldName. * @param mixed $options An array of HTML attributes, or a string, to be used as a class name. * @return string The formatted LABEL element