Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 0065005f95a9df7f2c39f6bc193532d9000efb34 1 parent c48d979
Mark Story markstory authored
7 cake/libs/view/helpers/form.php
View
@@ -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) {
13 cake/tests/cases/libs/view/helpers/form.test.php
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.