Skip to content

Commit

Permalink
Fix input type inference when type=>checkbox
Browse files Browse the repository at this point in the history
FormHelper should not infer types when the explicit type is checkbox.
Instead the provided type should be used.

Fixes #2491
  • Loading branch information
markstory committed Dec 17, 2013
1 parent 81d14e4 commit 30e1394
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -2851,6 +2851,34 @@ public function testInputOverridingMagicSelectType() {
$this->assertTags($result, $expected);
}

/**
* Test that inferred types do not override developer input
*
* @return void
*/
public function testInputMagicTypeDoesNotOverride() {
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.user', array('type' => 'checkbox'));
$expected = array(
'div' => array('class' => 'input checkbox'),
array('input' => array(
'type' => 'hidden',
'name' => 'data[Model][user]',
'id' => 'ModelUser_',
'value' => 0,
)),
array('input' => array(
'name' => 'data[Model][user]',
'type' => 'checkbox',
'id' => 'ModelUser',
'value' => 1
)),
'label' => array('for' => 'ModelUser'), 'User', '/label',
'/div'
);
$this->assertTags($result, $expected);
}

/**
* Test that magic input() selects are created for type=number
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -1082,7 +1082,7 @@ protected function _parseOptions($options) {
$options = $this->_magicOptions($options);
}

if (in_array($options['type'], array('checkbox', 'radio', 'select'))) {
if (in_array($options['type'], array('radio', 'select'))) {
$options = $this->_optionsOptions($options);
}

Expand Down

0 comments on commit 30e1394

Please sign in to comment.