mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #909 from dereuromark/master-magic-input-bc
Master magic input bc Fixes #3295
This commit is contained in:
commit
555bfc32ea
2 changed files with 37 additions and 2 deletions
|
@ -2623,6 +2623,36 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
|
@ -994,7 +994,7 @@ class FormHelper extends AppHelper {
|
|||
|
||||
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 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
$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'];
|
||||
|
|
Loading…
Reference in a new issue