Skip to content
Permalink
Browse files

Convert value to selected in SelectBox.

Having consistency between checkbox, select, and radio is more important
than keeping the code stable at this point.
  • Loading branch information...
markstory committed Jan 12, 2014
1 parent 567a65c commit 3d33cdc0b4074a7248e93fa20ccba4d2f858c1b9
Showing with 12 additions and 12 deletions.
  1. +4 −4 src/View/Input/SelectBox.php
  2. +8 −8 tests/TestCase/View/Input/SelectBoxTest.php
@@ -51,7 +51,7 @@ public function __construct($templates) {
* - `options` - An array of options.
* - `disabled` - Either true or an array of options to disable.
* When true, the select element will be disabled.
* - `value` - Either a string or an array of options to mark as selected.
* - `selected` - Either a string or an array of options to mark as selected.
* - `empty` - Set to true to add an empty option at the top of the
* option elements. Set to a string to define the display value of the
* empty option.
@@ -121,15 +121,15 @@ public function render($data) {
'escape' => true,
'options' => [],
'disabled' => null,
'value' => null,
'selected' => null,
];
if (empty($data['name'])) {
throw new \RuntimeException('Cannot make inputs with empty name attributes.');
}
$options = $this->_renderContent($data);
$name = $data['name'];
unset($data['name'], $data['options'], $data['empty'], $data['value'], $data['escape']);
unset($data['name'], $data['options'], $data['empty'], $data['selected'], $data['escape']);
if (isset($data['disabled']) && is_array($data['disabled'])) {
unset($data['disabled']);
}
@@ -168,7 +168,7 @@ protected function _renderContent($data) {
return [];
}
$selected = isset($data['value']) ? $data['value'] : null;
$selected = isset($data['selected']) ? $data['selected'] : null;
$disabled = null;
if (isset($data['disabled']) && is_array($data['disabled'])) {
$disabled = $data['disabled'];
@@ -141,7 +141,7 @@ public function testRenderSelected() {
$data = [
'id' => 'BirdName',
'name' => 'Birds[name]',
'value' => '1',
'selected' => '1',
'options' => [
1 => 'one',
'1x' => 'one x',
@@ -160,7 +160,7 @@ public function testRenderSelected() {
];
$this->assertTags($result, $expected);
$data['value'] = 2;
$data['selected'] = 2;
$result = $select->render($data);
$expected = [
'select' => ['name' => 'Birds[name]', 'id' => 'BirdName'],
@@ -211,7 +211,7 @@ public function testRenderMultipleSelected() {
'multiple' => true,
'id' => 'BirdName',
'name' => 'Birds[name]',
'value' => ['1', '2', 'burp'],
'selected' => ['1', '2', 'burp'],
'options' => [
1 => 'one',
'1x' => 'one x',
@@ -373,7 +373,7 @@ public function testRenderOptionGroupsSelectedAndDisabled() {
$select = new SelectBox($this->templates);
$data = [
'name' => 'Birds[name]',
'value' => ['1', '2', 'burp'],
'selected' => ['1', '2', 'burp'],
'disabled' => ['1x', '2x', 'nope'],
'options' => [
'ones' => [
@@ -416,7 +416,7 @@ public function testRenderDisabled() {
'disabled' => true,
'name' => 'Birds[name]',
'options' => ['a' => 'Albatross', 'b' => 'Budgie'],
'value' => 'a',
'selected' => 'a',
];
$result = $select->render($data);
$expected = [
@@ -440,7 +440,7 @@ public function testRenderDisabledMultiple() {
$select = new SelectBox($this->templates);
$data = [
'disabled' => ['a', 'c'],
'value' => 'a',
'selected' => 'a',
'name' => 'Birds[name]',
'options' => [
'a' => 'Albatross',
@@ -502,7 +502,7 @@ public function testRenderEmptyOption() {
$this->assertTags($result, $expected);
$data['empty'] = 'empty';
$data['value'] = '';
$data['selected'] = '';
$result = $select->render($data);
$expected = [
'select' => ['name' => 'Birds[name]', 'id' => 'BirdName'],
@@ -513,7 +513,7 @@ public function testRenderEmptyOption() {
];
$this->assertTags($result, $expected);
$data['value'] = false;
$data['selected'] = false;
$result = $select->render($data);
$this->assertTags($result, $expected);
}

0 comments on commit 3d33cdc

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