Skip to content
Permalink
Browse files

Fixing magic select creation for fields that have plural variables ad…

…ded to the view.
  • Loading branch information...
markstory committed Feb 20, 2010
1 parent 6285f78 commit 3192e130af816319941c7194c8410541de2bb0a4
Showing with 23 additions and 1 deletion.
  1. +8 −1 cake/libs/view/helpers/form.php
  2. +15 −0 cake/tests/cases/libs/view/helpers/form.test.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;
}
}
@@ -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);
}
/**

0 comments on commit 3192e13

Please sign in to comment.
You can’t perform that action at this time.