Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing FormHelper::__selectOptions incorrectly selecting options due …

…to type juggling. Fixes #167
  • Loading branch information...
commit 2675bbcd53ca3bad4aa9c9dabda0f8f9d0972dae 1 parent a36c2ec
@markstory markstory authored
View
2  cake/libs/view/helpers/form.php
@@ -1721,7 +1721,7 @@ function __selectOptions($elements = array(), $selected = null, $parents = array
}
if ($name !== null) {
- if ((!$selectedIsEmpty && $selected == $name) || ($selectedIsArray && in_array($name, $selected))) {
+ if ((!$selectedIsEmpty && (string)$selected == (string)$name) || ($selectedIsArray && in_array($name, $selected))) {
if ($attributes['style'] === 'checkbox') {
$htmlOptions['checked'] = true;
} else {
View
17 cake/tests/cases/libs/view/helpers/form.test.php
@@ -2687,6 +2687,23 @@ function testSelect() {
'/select'
);
$this->assertTags($result, $expected);
+
+ $this->Form->data = array('Model' => array('contact_id' => 228));
+ $result = $this->Form->select(
+ 'Model.contact_id',
+ array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'),
+ null, array('escape' => false), 'pick something'
+ );
+
+ $expected = array(
+ 'select' => array('name' => 'data[Model][contact_id]', 'id' => 'ModelContactId'),
+ array('option' => array('value' => '')), 'pick something', '/option',
+ array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option',
+ array('option' => array('value' => '228-1')), '228-1 value', '/option',
+ array('option' => array('value' => '228-2')), '228-2 value', '/option',
+ '/select'
+ );
+ $this->assertTags($result, $expected);
}
/**
* Tests that FormHelper::select() allows null to be passed in the $attributes parameter
Please sign in to comment.
Something went wrong with that request. Please try again.