Skip to content

Commit

Permalink
Fixed bug where default class name 'checkbox' was dropped in case of …
Browse files Browse the repository at this point in the history
…validation error for div wrapping checkbox for multiple checkboxes
  • Loading branch information
ADmad committed Mar 11, 2011
1 parent 5bb1730 commit 0f341c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cake/libs/view/helpers/form.php
Expand Up @@ -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' => '',
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 37 additions & 1 deletion cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -6349,7 +6385,7 @@ function testFormEnd() {
'/form'
);
$this->assertTags($result, $expected);

$result = $this->Form->end(array('label' => ''));
$expected = array(
'div' => array('class' => 'submit'),
Expand Down

0 comments on commit 0f341c7

Please sign in to comment.