From ee08fe5c1fff0ba5c0e7fcc07df90d1ff3f83bd1 Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 30 Jan 2013 13:54:09 +0100 Subject: [PATCH] BC fixes for disabled checkboxes see: d504642 see: #3545 Signed-off-by: Rachman Chavik --- .../Test/Case/View/Helper/FormHelperTest.php | 69 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 12 ++-- 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index a62dc725f..f061ba76d 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2445,6 +2445,33 @@ class FormHelperTest extends CakeTestCase { ); $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); } /** @@ -4277,6 +4304,48 @@ class FormHelperTest extends CakeTestCase { '/select' ); $this->assertTags($result, $expected); + + // make sure only 50 is selected, 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); } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 2198bfb8a..d4cdb9b6a 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2631,19 +2631,21 @@ class FormHelper extends AppHelper { 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']; }