Fix input type inference when type=>checkbox

FormHelper should not infer types when the explicit type is checkbox.
Instead the provided type should be used.

Fixes #2491
This commit is contained in:
mark_story 2013-12-16 23:26:20 -05:00
parent 81d14e4f1a
commit 30e139412d
2 changed files with 29 additions and 1 deletions

View file

@ -2851,6 +2851,34 @@ class FormHelperTest extends CakeTestCase {
$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
*

View file

@ -1082,7 +1082,7 @@ class FormHelper extends AppHelper {
$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);
}