Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing custom error class not being used if error for field is a name…
…d index. Test case added. Fixes #76
  • Loading branch information
markstory committed Sep 10, 2009
1 parent c48d979 commit 0065005
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions cake/libs/view/helpers/form.php
Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -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'));
Expand All @@ -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
Expand Down

0 comments on commit 0065005

Please sign in to comment.