Skip to content
Permalink
Browse files

Fixing automatic detection of select type based on variables present in

the view
  • Loading branch information...
lorenzo committed Feb 23, 2014
1 parent bc406cc commit f02c8af18e026f0f01a34fb0f2e9212f7f81e15f
Showing with 8 additions and 8 deletions.
  1. +4 −3 src/View/Helper/FormHelper.php
  2. +4 −5 tests/TestCase/View/Helper/FormHelperTest.php
@@ -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;
}
@@ -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))
);
@@ -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);
@@ -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',

0 comments on commit f02c8af

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