Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update textarea() to use new widget features.

Add name attribute parsing back in. Converting name attributes is still
required as marshalling code expects arrays from the POST data.
  • Loading branch information...
commit a1a3122b24070d04b1a310f242ab6d73294ca4b5 1 parent 095be56
@markstory markstory authored
View
17 src/View/Helper/FormHelper.php
@@ -173,6 +173,7 @@ class FormHelper extends Helper {
'formend' => '</form>',
'hiddenblock' => '<div style="display:none;">{{content}}</div>',
'input' => '<input type="{{type}}" name="{{name}}"{{attrs}}>',
+ 'textarea' => '<textarea name="{{name}}"{{attrs}}>{{value}}</textarea>',
];
/**
@@ -1568,14 +1569,18 @@ public function textarea($fieldName, $options = array()) {
$options = $this->_initInputField($fieldName, $options);
$value = null;
- if (array_key_exists('value', $options)) {
- $value = $options['value'];
+ if (array_key_exists('val', $options)) {
+ $value = $options['val'];
if (!array_key_exists('escape', $options) || $options['escape'] !== false) {
$value = h($value);
}
- unset($options['value']);
}
- return $this->Html->useTag('textarea', $options['name'], array_diff_key($options, array('type' => null, 'name' => null)), $value);
+ unset($options['val']);
+ return $this->formatTemplate('textarea', [
+ 'name' => $options['name'],
+ 'value' => $value,
+ 'attrs' => $this->_templater->formatAttributes($options, ['name']),
+ ]);
}
/**
@@ -2852,7 +2857,9 @@ protected function _initInputField($field, $options = []) {
}
if (!isset($options['name'])) {
- $options['name'] = $field;
+ $parts = explode('.', $field);
+ $first = array_shift($parts);
+ $options['name'] = $first . ($parts ? '[' . implode('][', $parts) . ']' : '');
}
if (isset($options['value']) && !isset($options['val'])) {
$options['val'] = $options['value'];
View
55 tests/TestCase/View/Helper/FormHelperTest.php
@@ -7753,45 +7753,45 @@ public function testInputDateMaxYear() {
* @return void
*/
public function testTextArea() {
- $this->markTestIncomplete('Need to revisit once models work again.');
- $this->Form->request->data = array('Model' => array('field' => 'some test data'));
- $result = $this->Form->textarea('Model.field');
+ $this->Form->request->data = array('field' => 'some test data');
+ $result = $this->Form->textarea('field');
$expected = array(
- 'textarea' => array('name' => 'Model[field]', 'id' => 'ModelField'),
+ 'textarea' => array('name' => 'field'),
'some test data',
'/textarea',
);
$this->assertTags($result, $expected);
- $result = $this->Form->textarea('Model.tmp');
+ $result = $this->Form->textarea('user.bio');
$expected = array(
- 'textarea' => array('name' => 'Model[tmp]', 'id' => 'ModelTmp'),
+ 'textarea' => array('name' => 'user[bio]'),
'/textarea',
);
$this->assertTags($result, $expected);
- $this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
- $result = $this->Form->textarea('Model.field');
+ $this->Form->request->data = array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars');
+ $result = $this->Form->textarea('field');
$expected = array(
- 'textarea' => array('name' => 'Model[field]', 'id' => 'ModelField'),
+ 'textarea' => array('name' => 'field'),
htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'),
'/textarea',
);
$this->assertTags($result, $expected);
- $this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
- $result = $this->Form->textarea('Model.field', array('escape' => false));
+ $this->Form->request->data = [
+ 'Model' => ['field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars']
+ ];
+ $result = $this->Form->textarea('Model.field', ['escape' => false]);
$expected = array(
- 'textarea' => array('name' => 'Model[field]', 'id' => 'ModelField'),
+ 'textarea' => array('name' => 'Model[field]'),
'some <strong>test</strong> data with <a href="#">HTML</a> chars',
'/textarea',
);
$this->assertTags($result, $expected);
- $this->Form->request->data['Model']['0']['OtherModel']['field'] = null;
- $result = $this->Form->textarea('Model.0.OtherModel.field');
+ $result = $this->Form->textarea('0.OtherModel.field');
$expected = array(
- 'textarea' => array('name' => 'Model[0][OtherModel][field]', 'id' => 'Model0OtherModelField'),
+ 'textarea' => array('name' => '0[OtherModel][field]'),
'/textarea'
);
$this->assertTags($result, $expected);
@@ -7805,21 +7805,16 @@ public function testTextArea() {
* @return void
*/
public function testTextAreaWithStupidCharacters() {
- $this->markTestIncomplete('Need to revisit once models work again.');
- $this->loadFixtures('Post');
- $result = $this->Form->input('Post.content', array(
- 'label' => 'Current Text', 'value' => "GREAT®", 'rows' => '15', 'cols' => '75'
- ));
- $expected = array(
- 'div' => array('class' => 'input textarea'),
- 'label' => array('for' => 'PostContent'),
- 'Current Text',
- '/label',
- 'textarea' => array('name' => 'Post[content]', 'id' => 'PostContent', 'rows' => '15', 'cols' => '75'),
- 'GREAT®',
- '/textarea',
- '/div'
- );
+ $result = $this->Form->textarea('Post.content', [
+ 'value' => "GREAT®",
+ 'rows' => '15',
+ 'cols' => '75'
+ ]);
+ $expected = [
+ 'textarea' => ['name' => 'Post[content]', 'rows' => '15', 'cols' => '75'],
+ 'GREAT®',
+ '/textarea',
+ ];
$this->assertTags($result, $expected);
}
Please sign in to comment.
Something went wrong with that request. Please try again.