Skip to content

Commit

Permalink
Add trailing [] to multi select.
Browse files Browse the repository at this point in the history
This is needed to make PHP get an array of values back instead of
a single value.
  • Loading branch information
markstory committed Jan 9, 2014
1 parent 8e71c0a commit bd448bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion Cake/View/Input/SelectBox.php
Expand Up @@ -134,8 +134,13 @@ public function render($data) {
unset($data['disabled']);
}

$template = 'select';
if (!empty($data['multiple'])) {
$template = 'selectMultiple';
unset($data['multiple']);
}
$attrs = $this->_templates->formatAttributes($data);
return $this->_templates->format('select', [
return $this->_templates->format($template, [
'name' => $name,
'attrs' => $attrs,
'content' => implode('', $options),
Expand Down
7 changes: 4 additions & 3 deletions Test/TestCase/View/Input/SelectBoxTest.php
Expand Up @@ -27,6 +27,7 @@ public function setUp() {
parent::setUp();
$templates = [
'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',
'selectMultiple' => '<select name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>',
'option' => '<option value="{{name}}"{{attrs}}>{{value}}</option>',
'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
];
Expand Down Expand Up @@ -188,7 +189,7 @@ public function testRenderMultipleSelect() {
$result = $select->render($data);
$expected = [
'select' => [
'name' => 'Birds[name]',
'name' => 'Birds[name][]',
'id' => 'BirdName',
'multiple' => 'multiple',
],
Expand All @@ -209,7 +210,7 @@ public function testRenderMultipleSelected() {
$data = [
'multiple' => true,
'id' => 'BirdName',
'name' => 'Birds[name]',
'name' => 'Birds[name][]',
'value' => ['1', '2', 'burp'],
'options' => [
1 => 'one',
Expand All @@ -221,7 +222,7 @@ public function testRenderMultipleSelected() {
$result = $select->render($data);
$expected = [
'select' => [
'name' => 'Birds[name]',
'name' => 'Birds[name][]',
'multiple' => 'multiple',
'id' => 'BirdName'
],
Expand Down

0 comments on commit bd448bc

Please sign in to comment.