Permalink
Browse files

Fixed bug where default class name 'checkbox' was dropped in case of …

…validation error for div wrapping checkbox for multiple checkboxes
  • Loading branch information...
1 parent 5bb1730 commit 0f341c711431bbc1b9d2f316d7e1a1473416753d @ADmad ADmad committed Mar 11, 2011
Showing with 41 additions and 3 deletions.
  1. +4 −2 cake/libs/view/helpers/form.php
  2. +37 −1 cake/tests/cases/libs/view/helpers/form.test.php
@@ -1422,7 +1422,7 @@ function select($fieldName, $options = array(), $selected = null, $attributes =
$style = null;
$tag = null;
$attributes += array(
- 'class' => null,
+ 'class' => null,
'escape' => true,
'secure' => null,
'empty' => '',
@@ -2048,6 +2048,8 @@ function __selectOptions($elements = array(), $selected = null, $parents = array
if (empty($attributes['class'])) {
$attributes['class'] = 'checkbox';
+ } elseif ($attributes['class'] === 'form-error') {
+ $attributes['class'] = 'checkbox ' . $attributes['class'];
}
$label = $this->label(null, $title, $label);
$item = sprintf(
@@ -2189,7 +2191,7 @@ function _initInputField($field, $options = array()) {
} else {
$secure = (isset($this->params['_Token']) && !empty($this->params['_Token']));
}
-
+
$fieldName = null;
if ($secure && !empty($options['name'])) {
preg_match_all('/\[(.*?)\]/', $options['name'], $matches);
@@ -3589,6 +3589,42 @@ function testSelectMultipleCheckboxDiv() {
'label' => false
));
$this->assertTags($result, $expected);
+
+ $this->Form->validationErrors['Model']['tags'] = 'Select atleast one option';
+ $result = $this->Form->input('Model.tags', array(
+ 'options' => array('one'),
+ 'multiple' => 'checkbox',
+ 'label' => false,
+ 'div' => false
+ ));
+ $expected = array(
+ 'input' => array('type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'),
+ array('div' => array('class' => 'checkbox form-error')),
+ array('input' => array('type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0')),
+ array('label' => array('for' => 'ModelTags0')),
+ 'one',
+ '/label',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Form->input('Model.tags', array(
+ 'options' => array('one'),
+ 'multiple' => 'checkbox',
+ 'class' => 'mycheckbox',
+ 'label' => false,
+ 'div' => false
+ ));
+ $expected = array(
+ 'input' => array('type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'),
+ array('div' => array('class' => 'mycheckbox form-error')),
+ array('input' => array('type' => 'checkbox', 'name' => 'data[Model][tags][]', 'value' => '0', 'id' => 'ModelTags0')),
+ array('label' => array('for' => 'ModelTags0')),
+ 'one',
+ '/label',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
}
/**
@@ -6349,7 +6385,7 @@ function testFormEnd() {
'/form'
);
$this->assertTags($result, $expected);
-
+
$result = $this->Form->end(array('label' => ''));
$expected = array(
'div' => array('class' => 'submit'),

0 comments on commit 0f341c7

Please sign in to comment.