Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Master magic input bc #909

Merged
merged 4 commits into from

3 participants

@ADmad
Collaborator

How about moving the new tests to a more appropriate function than testInputWithMatchingFieldAndModelName()

@dereuromark
Collaborator

what do you propose?

testInputWithMagicSelect()

@ADmad
Collaborator

testInputWithMagicSelectForNumericField() :smile:

@dereuromark
Collaborator

testInputMagicSelectForTypeNumber - as testInputMagicSelectChangeToRadio comes next then

lib/Cake/View/Helper/FormHelper.php
((8 lines not shown))
}
$autoLength = (
!array_key_exists('maxlength', $options) &&
isset($fieldDef['length']) &&
- is_scalar($fieldDef['length'])
+ is_scalar($fieldDef['length']) &&
+ $options['type'] !== 'select'
@markstory Owner

Funny whitespace here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@markstory
Owner

So if I understand the point of this, it allows fields with the inferred type of number/text that have matching inflected variables to create select boxes? Doesn't that create the possibility of inputs that used to be text/number to magically swap into select boxes when upgrading?

@dereuromark
Collaborator

well, the current way of doing things breaks BC for sure. at least compared to 1.3. as my lighthouseapp example shows.
new cake2.x apps could possibly run into your issue, yes.

@markstory
Owner

Ah I missed the link to the lighthouse issue. With that information I think this makes a bit more sense to fix then.

@markstory markstory merged commit 555bfc3 into cakephp:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
30 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -2615,6 +2615,36 @@ public function testInputOverridingMagicSelectType() {
}
/**
+ * Test that magic input() selects are created for type=number
+ *
+ * @return void
+ */
+ public function testInputMagicSelectForTypeNumber() {
+ $this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot');
+ $this->Form->request->data = array('ValidateUser' => array('balance' => 1));
+ $result = $this->Form->input('ValidateUser.balance');
+ $expected = array(
+ 'div' => array('class' => 'input select'),
+ 'label' => array('for' => 'ValidateUserBalance'),
+ 'Balance',
+ '/label',
+ 'select' => array('name' => 'data[ValidateUser][balance]', 'id' => 'ValidateUserBalance'),
+ array('option' => array('value' => '0')),
+ 'nothing',
+ '/option',
+ array('option' => array('value' => '1', 'selected' => 'selected')),
+ 'some',
+ '/option',
+ array('option' => array('value' => '100')),
+ 'a lot',
+ '/option',
+ '/select',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+ }
+
+/**
* Test that magic input() selects can easily be converted into radio types without error.
*
* @return void
View
9 lib/Cake/View/Helper/FormHelper.php
@@ -994,7 +994,7 @@ public function input($fieldName, $options = array()) {
if (
(!isset($options['options']) && in_array($options['type'], $types)) ||
- (isset($magicType) && $options['type'] == 'text')
+ (isset($magicType) && in_array($options['type'], array('text', 'number')))
) {
$varName = Inflector::variable(
Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey))
@@ -1006,12 +1006,17 @@ public function input($fieldName, $options = array()) {
}
$options['options'] = $varOptions;
}
+
+ if ($options['type'] === 'select' && array_key_exists('step', $options)) {
+ unset($options['step']);
+ }
}
$autoLength = (
!array_key_exists('maxlength', $options) &&
isset($fieldDef['length']) &&
- is_scalar($fieldDef['length'])
+ is_scalar($fieldDef['length']) &&
+ $options['type'] !== 'select'
);
if ($autoLength && $options['type'] == 'text') {
$options['maxlength'] = $fieldDef['length'];
Something went wrong with that request. Please try again.