mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fix maxlength for manual type set and add textarea maxlength support.
This commit is contained in:
parent
3fb252ad2f
commit
03d92494f1
2 changed files with 42 additions and 7 deletions
|
@ -2046,7 +2046,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'Email',
|
'Email',
|
||||||
'/label',
|
'/label',
|
||||||
array('input' => array(
|
array('input' => array(
|
||||||
'type' => 'text', 'name' => 'data[Contact][email]',
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
|
||||||
'id' => 'ContactEmail'
|
'id' => 'ContactEmail'
|
||||||
)),
|
)),
|
||||||
'/div'
|
'/div'
|
||||||
|
@ -2060,7 +2060,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'Email',
|
'Email',
|
||||||
'/label',
|
'/label',
|
||||||
array('input' => array(
|
array('input' => array(
|
||||||
'type' => 'text', 'name' => 'data[Contact][5][email]',
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][5][email]',
|
||||||
'id' => 'Contact5Email'
|
'id' => 'Contact5Email'
|
||||||
)),
|
)),
|
||||||
'/div'
|
'/div'
|
||||||
|
@ -7464,6 +7464,37 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test textareas waxlength read from schema.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTextAreaMaxLength() {
|
||||||
|
$result = $this->Form->input('UserForm.other', array('type' => 'textarea'));
|
||||||
|
$expected = array(
|
||||||
|
'div' => array('class' => 'input textarea'),
|
||||||
|
'label' => array('for' => 'UserFormOther'),
|
||||||
|
'Other',
|
||||||
|
'/label',
|
||||||
|
'textarea' => array('name' => 'data[UserForm][other]', 'cols' => '30', 'rows' => '6', 'id' => 'UserFormOther'),
|
||||||
|
'/textarea',
|
||||||
|
'/div'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Form->input('UserForm.stuff', array('type' => 'textarea'));
|
||||||
|
$expected = array(
|
||||||
|
'div' => array('class' => 'input textarea'),
|
||||||
|
'label' => array('for' => 'UserFormStuff'),
|
||||||
|
'Stuff',
|
||||||
|
'/label',
|
||||||
|
'textarea' => array('name' => 'data[UserForm][stuff]', 'maxlength' => 10, 'cols' => '30', 'rows' => '6', 'id' => 'UserFormStuff'),
|
||||||
|
'/textarea',
|
||||||
|
'/div'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testTextAreaWithStupidCharacters method
|
* testTextAreaWithStupidCharacters method
|
||||||
*
|
*
|
||||||
|
@ -9586,6 +9617,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'textarea' => array(
|
'textarea' => array(
|
||||||
'id' => 'ValidateProfile1ValidateItem2Name',
|
'id' => 'ValidateProfile1ValidateItem2Name',
|
||||||
'name' => 'data[ValidateProfile][1][ValidateItem][2][name]',
|
'name' => 'data[ValidateProfile][1][ValidateItem][2][name]',
|
||||||
|
'maxlength' => 255,
|
||||||
'cols' => 30,
|
'cols' => 30,
|
||||||
'rows' => 6
|
'rows' => 6
|
||||||
),
|
),
|
||||||
|
@ -9702,7 +9734,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'div' => array('class' => 'input text'),
|
'div' => array('class' => 'input text'),
|
||||||
'input' => array(
|
'input' => array(
|
||||||
'type' => 'text', 'name' => 'data[Contact][email]',
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
|
||||||
'id' => 'ContactEmail'
|
'id' => 'ContactEmail'
|
||||||
),
|
),
|
||||||
'/div'
|
'/div'
|
||||||
|
@ -9716,7 +9748,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'div' => array('class' => 'input text'),
|
'div' => array('class' => 'input text'),
|
||||||
array('input' => array(
|
array('input' => array(
|
||||||
'type' => 'text', 'name' => 'data[Contact][email]',
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
|
||||||
'id' => 'ContactEmail'
|
'id' => 'ContactEmail'
|
||||||
)),
|
)),
|
||||||
'label' => array('for' => 'ContactEmail'),
|
'label' => array('for' => 'ContactEmail'),
|
||||||
|
@ -9736,7 +9768,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'div' => array('class' => 'input text'),
|
'div' => array('class' => 'input text'),
|
||||||
array('input' => array(
|
array('input' => array(
|
||||||
'type' => 'text', 'name' => 'data[Contact][email]',
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
|
||||||
'id' => 'ContactEmail'
|
'id' => 'ContactEmail'
|
||||||
)),
|
)),
|
||||||
array('div' => array()),
|
array('div' => array()),
|
||||||
|
|
|
@ -1125,6 +1125,8 @@ class FormHelper extends AppHelper {
|
||||||
$options = $this->_optionsOptions($options);
|
$options = $this->_optionsOptions($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$options = $this->_maxLength($options);
|
||||||
|
|
||||||
if (isset($options['rows']) || isset($options['cols'])) {
|
if (isset($options['rows']) || isset($options['cols'])) {
|
||||||
$options['type'] = 'textarea';
|
$options['type'] = 'textarea';
|
||||||
}
|
}
|
||||||
|
@ -1228,7 +1230,7 @@ class FormHelper extends AppHelper {
|
||||||
if ($options['type'] === 'select' && array_key_exists('step', $options)) {
|
if ($options['type'] === 'select' && array_key_exists('step', $options)) {
|
||||||
unset($options['step']);
|
unset($options['step']);
|
||||||
}
|
}
|
||||||
$options = $this->_maxLength($options);
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1286,10 +1288,11 @@ class FormHelper extends AppHelper {
|
||||||
!array_key_exists('maxlength', $options) &&
|
!array_key_exists('maxlength', $options) &&
|
||||||
isset($fieldDef['length']) &&
|
isset($fieldDef['length']) &&
|
||||||
is_scalar($fieldDef['length']) &&
|
is_scalar($fieldDef['length']) &&
|
||||||
|
$fieldDef['length'] < 1000000 &&
|
||||||
$options['type'] !== 'select'
|
$options['type'] !== 'select'
|
||||||
);
|
);
|
||||||
if ($autoLength &&
|
if ($autoLength &&
|
||||||
in_array($options['type'], array('text', 'email', 'tel', 'url', 'search'))
|
in_array($options['type'], array('text', 'textarea', 'email', 'tel', 'url', 'search'))
|
||||||
) {
|
) {
|
||||||
$options['maxlength'] = $fieldDef['length'];
|
$options['maxlength'] = $fieldDef['length'];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue