Browse files

Fixing custom error class not being used if error for field is a name…

…d index. Test case added. Fixes #76
  • Loading branch information...
1 parent c48d979 commit 0065005f95a9df7f2c39f6bc193532d9000efb34 @markstory markstory committed Sep 10, 2009
Showing with 14 additions and 6 deletions.
  1. +3 −4 cake/libs/view/helpers/form.php
  2. +11 −2 cake/tests/cases/libs/view/helpers/form.test.php
View
7 cake/libs/view/helpers/form.php
@@ -408,11 +408,10 @@ function error($field, $text = null, $options = array()) {
if (is_array($text) && is_numeric($error) && $error > 0) {
$error--;
}
- if (is_array($text) && isset($text[$error])) {
- $text = $text[$error];
- } elseif (is_array($text)) {
+ if (is_array($text)) {
$options = array_merge($options, $text);
- $text = null;
+ $text = isset($text[$error]) ? $text[$error] : null;
+ unset($options[$error]);
}
if ($text != null) {
View
13 cake/tests/cases/libs/view/helpers/form.test.php
@@ -2235,14 +2235,14 @@ function testDefaultValue() {
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField')));
}
/**
- * testFieldError method
+ * testError method
*
* Test field error generation
*
* @access public
* @return void
*/
- function testFieldError() {
+ function testError() {
$this->Form->validationErrors['Model']['field'] = 1;
$result = $this->Form->error('Model.field');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
@@ -2269,6 +2269,15 @@ function testFieldError() {
$result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
$this->assertEqual($result, '<strong>Badness!</strong>');
+
+ $this->Form->validationErrors['Model']['field'] = "email";
+ $result = $this->Form->error('Model.field', array('class' => 'field-error', 'email' => 'No good!'));
+ $expected = array(
+ 'div' => array('class' => 'field-error'),
+ 'No good!',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
}
/**
* testPassword method

0 comments on commit 0065005

Please sign in to comment.