Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix BC for #3545 #1094

Closed
wants to merge 1 commit into from

3 participants

@dereuromark
Collaborator

Did not fast forward earlier.

@dereuromark dereuromark reopened this
@lorenzo
Owner

Maybe you want to add unit tests to that and make sure the other tests pass?

@rchavik
Collaborator

@dereuromark fyi, working on splitting this up to for 2.2.x and 2.3.x. PR coming soon.

updated PR:

@rchavik
Collaborator

note: split patch and merged in 2.2: d504642, and 2.3 (master): ee08fe5

@rchavik rchavik closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
71 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -2445,6 +2445,33 @@ public function testInputCheckboxWithDisabledElements() {
);
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
$this->assertTags($result, $expected);
+
+ // make sure 50 does only disable 50, and not 50f5c0cf
+ $options = array('50' => 'Fifty', '50f5c0cf' => 'Stringy');
+ $disabled = array(50);
+
+ $expected = array(
+ array('div' => array('class' => 'input select')),
+ array('label' => array('for' => "ContactMultiple")),
+ 'Multiple',
+ '/label',
+ array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
+ array('div' => array('class' => 'checkbox')),
+ array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 50, 'disabled' => 'disabled', 'id' => "ContactMultiple50")),
+ array('label' => array('for' => "ContactMultiple50")),
+ 'Fifty',
+ '/label',
+ '/div',
+ array('div' => array('class' => 'checkbox')),
+ array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => '50f5c0cf', 'id' => "ContactMultiple50f5c0cf")),
+ array('label' => array('for' => "ContactMultiple50f5c0cf")),
+ 'Stringy',
+ '/label',
+ '/div',
+ '/div'
+ );
+ $result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
+ $this->assertTags($result, $expected);
}
/**
@@ -4246,7 +4273,7 @@ public function testHabtmSelectBox() {
'Contact' => array(),
'ContactTag' => array(
array(
- 'id' => 1,
+ 'id' => '1',
'name' => 'blue'
),
array(
@@ -4277,6 +4304,48 @@ public function testHabtmSelectBox() {
'/select'
);
$this->assertTags($result, $expected);
+
+ // make sure 50 does only select 50, and not 50f5c0cf
+ $this->View->viewVars['contactTags'] = array(
+ '1' => 'blue',
+ '50f5c0cf' => 'red',
+ '50' => 'green'
+ );
+ $this->Form->request->data = array(
+ 'Contact' => array(),
+ 'ContactTag' => array(
+ array(
+ 'id' => 1,
+ 'name' => 'blue'
+ ),
+ array(
+ 'id' => 50,
+ 'name' => 'green'
+ )
+ )
+ );
+ $this->Form->create('Contact');
+ $result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
+ $expected = array(
+ 'input' => array(
+ 'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
+ ),
+ 'select' => array(
+ 'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
+ 'multiple' => 'multiple'
+ ),
+ array('option' => array('value' => '1', 'selected' => 'selected')),
+ 'blue',
+ '/option',
+ array('option' => array('value' => '50f5c0cf')),
+ 'red',
+ '/option',
+ array('option' => array('value' => '50', 'selected' => 'selected')),
+ 'green',
+ '/option',
+ '/select'
+ );
+ $this->assertTags($result, $expected);
}
/**
View
15 lib/Cake/View/Helper/FormHelper.php
@@ -2613,9 +2613,10 @@ protected function _selectOptions($elements = array(), $parents = array(), $show
}
if ($name !== null) {
+ $isNumeric = is_numeric($name);
if (
(!$selectedIsArray && !$selectedIsEmpty && (string)$attributes['value'] == (string)$name) ||
- ($selectedIsArray && in_array($name, $attributes['value'], true))
+ ($selectedIsArray && in_array($name, $attributes['value'], !$isNumeric))
) {
if ($attributes['style'] === 'checkbox') {
$htmlOptions['checked'] = true;
@@ -2630,19 +2631,21 @@ protected function _selectOptions($elements = array(), $parents = array(), $show
if ($attributes['style'] === 'checkbox') {
$htmlOptions['value'] = $name;
- $disabledType = null;
$hasDisabled = !empty($attributes['disabled']);
if ($hasDisabled) {
- $disabledType = gettype($attributes['disabled']);
+ $disabledIsArray = is_array($attributes['disabled']);
+ if ($disabledIsArray) {
+ $disabledIsNumeric = is_numeric($htmlOptions['value']);
+ }
}
if (
$hasDisabled &&
- $disabledType === 'array' &&
- in_array($htmlOptions['value'], $attributes['disabled'])
+ $disabledIsArray &&
+ in_array($htmlOptions['value'], $attributes['disabled'], !$disabledIsNumeric)
) {
$htmlOptions['disabled'] = 'disabled';
}
- if ($hasDisabled && $disabledType !== 'array') {
+ if ($hasDisabled && !$disabledIsArray) {
$htmlOptions['disabled'] = $attributes['disabled'] === true ? 'disabled' : $attributes['disabled'];
}
Something went wrong with that request. Please try again.