diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index c6b5c4906b0..5b427b60006 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -674,6 +674,7 @@ function input($fieldName, $options = array()) { } if (!isset($options['type'])) { + $magicType = true; $options['type'] = 'text'; $fieldDef = array(); if (isset($options['options'])) { @@ -716,13 +717,19 @@ function input($fieldName, $options = array()) { } $types = array('checkbox', 'radio', 'select'); - if (!isset($options['options']) && in_array($options['type'], $types)) { + if ( + (!isset($options['options']) && in_array($options['type'], $types)) || + (isset($magicType) && $options['type'] == 'text') + ) { $view =& ClassRegistry::getObject('view'); $varName = Inflector::variable( Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey)) ); $varOptions = $view->getVar($varName); if (is_array($varOptions)) { + if ($options['type'] !== 'radio') { + $options['type'] = 'select'; + } $options['options'] = $varOptions; } } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 1469ef9396c..45876419b11 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -2061,6 +2061,21 @@ function testInputOverridingMagicSelectType() { '/div' ); $this->assertTags($result, $expected); + + //Check that magic types still work for plural/singular vars + $view =& ClassRegistry::getObject('view'); + $view->viewVars['types'] = array('value' => 'good', 'other' => 'bad'); + $result = $this->Form->input('Model.type'); + $expected = array( + 'div' => array('class' => 'input select'), + 'label' => array('for' => 'ModelType'), 'Type', '/label', + 'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'), + array('option' => array('value' => 'value')), 'good', '/option', + array('option' => array('value' => 'other')), 'bad', '/option', + '/select', + '/div' + ); + $this->assertTags($result, $expected); } /**