Skip to content

Commit

Permalink
Fixing automatic detection of select type based on variables present in
Browse files Browse the repository at this point in the history
the view
  • Loading branch information
lorenzo committed Feb 23, 2014
1 parent bc406cc commit f02c8af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/View/Helper/FormHelper.php
Expand Up @@ -925,13 +925,13 @@ protected function _getInput($fieldName, $options) {
* @return array Options
*/
protected function _parseOptions($fieldName, $options) {
$typePassed = true;
$needsMagicType = false;
if (empty($options['type'])) {
$typePassed = false;
$needsMagicType = true;
$options['type'] = $this->_inputType($fieldName, $options);
}

$options = $this->_magicOptions($fieldName, $options, $typePassed);
$options = $this->_magicOptions($fieldName, $options, $needsMagicType);
return $options;
}

Expand Down Expand Up @@ -992,6 +992,7 @@ protected function _optionsOptions($fieldName, $options) {
return $options;
}

$fieldName = array_slice(explode('.', $fieldName), -1)[0];
$varName = Inflector::variable(
Inflector::pluralize(preg_replace('/_id$/', '', $fieldName))
);
Expand Down
9 changes: 4 additions & 5 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -3358,13 +3358,12 @@ public function testInputWithNonStandardPrimaryKeyMakesHidden() {
* @return void
*/
public function testInputOverridingMagicSelectType() {
$this->markTestIncomplete('Need to revisit once models work again.');
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.user_id', array('type' => 'text'));
$expected = array(
'div' => array('class' => 'input text'),
'label' => array('for' => 'ModelUserId'), 'User', '/label',
'input' => array('name' => 'Model[user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
'label' => array('for' => 'model-user-id'), 'User', '/label',
'input' => array('name' => 'Model[user_id]', 'type' => 'text', 'id' => 'model-user-id'),
'/div'
);
$this->assertTags($result, $expected);
Expand All @@ -3374,8 +3373,8 @@ public function testInputOverridingMagicSelectType() {
$result = $this->Form->input('Model.type');
$expected = array(
'div' => array('class' => 'input select'),
'label' => array('for' => 'ModelType'), 'Type', '/label',
'select' => array('name' => 'Model[type]', 'id' => 'ModelType'),
'label' => array('for' => 'model-type'), 'Type', '/label',
'select' => array('name' => 'Model[type]', 'id' => 'model-type'),
array('option' => array('value' => 'value')), 'good', '/option',
array('option' => array('value' => 'other')), 'bad', '/option',
'/select',
Expand Down

0 comments on commit f02c8af

Please sign in to comment.