Skip to content
Permalink
Browse files

Fix maxlength for manual type set and add textarea maxlength support.

  • Loading branch information...
dereuromark committed Sep 13, 2014
1 parent 3fb252a commit 03d92494f132df6ff6781ee6160ffe8405d25162
Showing with 42 additions and 7 deletions.
  1. +37 −5 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +5 −2 lib/Cake/View/Helper/FormHelper.php
@@ -2046,7 +2046,7 @@ public function testInput() {
'Email',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
'/div'
@@ -2060,7 +2060,7 @@ public function testInput() {
'Email',
'/label',
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][5][email]',
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][5][email]',
'id' => 'Contact5Email'
)),
'/div'
@@ -7464,6 +7464,37 @@ public function testTextArea() {
$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
*
@@ -9586,6 +9617,7 @@ public function testMultiRecordForm() {
'textarea' => array(
'id' => 'ValidateProfile1ValidateItem2Name',
'name' => 'data[ValidateProfile][1][ValidateItem][2][name]',
'maxlength' => 255,
'cols' => 30,
'rows' => 6
),
@@ -9702,7 +9734,7 @@ public function testInputTemplate() {
$expected = array(
'div' => array('class' => 'input text'),
'input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
),
'/div'
@@ -9716,7 +9748,7 @@ public function testInputTemplate() {
$expected = array(
'div' => array('class' => 'input text'),
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
'label' => array('for' => 'ContactEmail'),
@@ -9736,7 +9768,7 @@ public function testInputTemplate() {
$expected = array(
'div' => array('class' => 'input text'),
array('input' => array(
'type' => 'text', 'name' => 'data[Contact][email]',
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
'id' => 'ContactEmail'
)),
array('div' => array()),
@@ -1125,6 +1125,8 @@ protected function _parseOptions($options) {
$options = $this->_optionsOptions($options);
}
$options = $this->_maxLength($options);
if (isset($options['rows']) || isset($options['cols'])) {
$options['type'] = 'textarea';
}
@@ -1228,7 +1230,7 @@ protected function _magicOptions($options) {
if ($options['type'] === 'select' && array_key_exists('step', $options)) {
unset($options['step']);
}
$options = $this->_maxLength($options);
return $options;
}
@@ -1286,10 +1288,11 @@ protected function _maxLength($options) {
!array_key_exists('maxlength', $options) &&
isset($fieldDef['length']) &&
is_scalar($fieldDef['length']) &&
$fieldDef['length'] < 1000000 &&
$options['type'] !== 'select'
);
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'];
}

0 comments on commit 03d9249

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