Don't disable the entire select when disabled is array(1)

When the disabled attribute is just array(1), then the attribute should
be filtered out of select element attributes. This is kind of a hacky
workaround but changing the underlying attribute handling is going to be
pretty tricky and far more dangerous.

Fixes #3546
This commit is contained in:
mark_story 2014-05-23 13:26:11 -04:00
parent 81875cfeb1
commit db86b0c050
2 changed files with 9 additions and 5 deletions

View file

@ -4939,7 +4939,7 @@ class FormHelperTest extends CakeTestCase {
*/ */
public function testSelectMultipleWithDisabledElements() { public function testSelectMultipleWithDisabledElements() {
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy'); $options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
$disabled = array(2, 3); $disabled = array(1);
$result = $this->Form->select('Contact.multiple', $options, array('multiple' => 'multiple', 'disabled' => $disabled)); $result = $this->Form->select('Contact.multiple', $options, array('multiple' => 'multiple', 'disabled' => $disabled));
$expected = array( $expected = array(
'input' => array( 'input' => array(
@ -4948,13 +4948,13 @@ class FormHelperTest extends CakeTestCase {
'select' => array( 'select' => array(
'name' => 'data[Contact][multiple][]', 'multiple' => 'multiple', 'id' => 'ContactMultiple' 'name' => 'data[Contact][multiple][]', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
), ),
array('option' => array('value' => '1')), array('option' => array('value' => '1', 'disabled' => 'disabled')),
'One', 'One',
'/option', '/option',
array('option' => array('value' => '2', 'disabled' => 'disabled')), array('option' => array('value' => '2')),
'Two', 'Two',
'/option', '/option',
array('option' => array('value' => '3', 'disabled' => 'disabled')), array('option' => array('value' => '3')),
'Three', 'Three',
'/option', '/option',
array('option' => array('value' => '3x')), array('option' => array('value' => '3x')),

View file

@ -2091,7 +2091,11 @@ class FormHelper extends AppHelper {
) { ) {
$this->_secure(true, $this->_secureFieldName($attributes)); $this->_secure(true, $this->_secureFieldName($attributes));
} }
$select[] = $this->Html->useTag($tag, $attributes['name'], array_diff_key($attributes, array('name' => null, 'value' => null))); $filter = array('name' => null, 'value' => null);
if (is_array($attributes['disabled'])) {
$filter['disabled'] = null;
}
$select[] = $this->Html->useTag($tag, $attributes['name'], array_diff_key($attributes, $filter));
} }
$emptyMulti = ( $emptyMulti = (
$showEmpty !== null && $showEmpty !== false && !( $showEmpty !== null && $showEmpty !== false && !(