Permalink
Browse files

Add trailing [] to multi select.

This is needed to make PHP get an array of values back instead of
a single value.
  • Loading branch information...
1 parent 8e71c0a commit bd448bc54ab0924239bc7cedb9398345547fbe36 @markstory markstory committed Jan 9, 2014
Showing with 10 additions and 4 deletions.
  1. +6 −1 Cake/View/Input/SelectBox.php
  2. +4 −3 Test/TestCase/View/Input/SelectBoxTest.php
@@ -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),
@@ -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>',
];
@@ -188,7 +189,7 @@ public function testRenderMultipleSelect() {
$result = $select->render($data);
$expected = [
'select' => [
- 'name' => 'Birds[name]',
+ 'name' => 'Birds[name][]',
'id' => 'BirdName',
'multiple' => 'multiple',
],
@@ -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',
@@ -221,7 +222,7 @@ public function testRenderMultipleSelected() {
$result = $select->render($data);
$expected = [
'select' => [
- 'name' => 'Birds[name]',
+ 'name' => 'Birds[name][]',
'multiple' => 'multiple',
'id' => 'BirdName'
],

0 comments on commit bd448bc

Please sign in to comment.