Skip to content

Commit

Permalink
Making class attribute bubble down into FormHelper::__selectOption().
Browse files Browse the repository at this point in the history
Fixes issue where you couldn't change the classname of checkbox options.
Fixes #1202
  • Loading branch information
markstory committed Oct 16, 2010
1 parent 67874bd commit c35ef7d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cake/libs/view/helpers/form.php
Expand Up @@ -1438,6 +1438,7 @@ function select($fieldName, $options = array(), $selected = null, $attributes =
$attributes = $this->_initInputField($fieldName, array_merge(
(array)$attributes, array('secure' => false)
));
$attributes += array('class' => null);

if (is_string($options) && isset($this->__options[$options])) {
$options = $this->__generateOptions($options);
Expand Down Expand Up @@ -1498,7 +1499,7 @@ function select($fieldName, $options = array(), $selected = null, $attributes =
$selected,
array(),
$showParents,
array('escape' => $escapeOptions, 'style' => $style, 'name' => $attributes['name'])
array('escape' => $escapeOptions, 'style' => $style, 'name' => $attributes['name'], 'class' => $attributes['class'])
));

$template = ($style == 'checkbox') ? 'checkboxmultipleend' : 'selectend';
Expand Down Expand Up @@ -1982,7 +1983,7 @@ function _name($options = array(), $field = null, $key = 'name') {
*/
function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null, $attributes = array()) {
$select = array();
$attributes = array_merge(array('escape' => true, 'style' => null), $attributes);
$attributes = array_merge(array('escape' => true, 'style' => null, 'class' => null), $attributes);
$selectedIsEmpty = ($selected === '' || $selected === null);
$selectedIsArray = is_array($selected);

Expand Down
44 changes: 44 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -3508,6 +3508,50 @@ function testSelectMultipleCheckboxes() {
$this->assertTags($result, $expected);
}

/**
* test multiple checkboxes with div styles.
*
* @return void
*/
function testSelectMultipleCheckboxDiv() {
$result = $this->Form->select(
'Model.tags',
array('first', 'second'),
null,
array('multiple' => 'checkbox', 'class' => 'my-class')
);
$expected = array(
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
),
array('div' => array('class' => 'my-class')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
'value' => '0', 'id' => 'ModelTags0'
)),
array('label' => array('for' => 'ModelTags0')), 'first', '/label',
'/div',

array('div' => array('class' => 'my-class')),
array('input' => array(
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
'value' => '1', 'id' => 'ModelTags1'
)),
array('label' => array('for' => 'ModelTags1')), 'second', '/label',
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Model.tags', array(
'options' => array('first', 'second'),
'multiple' => 'checkbox',
'class' => 'my-class',
'div' => false,
'label' => false
));
$this->assertTags($result, $expected);
}

/**
* Checks the security hash array generated for multiple-input checkbox elements
*
Expand Down

0 comments on commit c35ef7d

Please sign in to comment.