Skip to content

Commit

Permalink
Port fixes from #5616 to 3.0.
Browse files Browse the repository at this point in the history
FormHelper shared the same issues in 3.0 as it did in 2.x. Given that
merging was going to be a nightmare, I've copy&paste merged these
changes on to 3.0.
  • Loading branch information
markstory committed Jan 11, 2015
1 parent 0b8b558 commit 5114ffe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/View/Helper/FormHelper.php
Expand Up @@ -1387,15 +1387,14 @@ public function checkbox($fieldName, array $options = [])
*/
public function radio($fieldName, $options = [], array $attributes = [])
{
$attributes['options'] = $options;
$attributes['idPrefix'] = $this->_idPrefix;
$attributes = $this->_initInputField($fieldName, $attributes);

$value = $attributes['val'];
$hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true;
unset($attributes['hiddenField']);

$attributes['options'] = $options;
$attributes['idPrefix'] = $this->_idPrefix;

$radio = $this->widget('radio', $attributes);

$hidden = '';
Expand Down Expand Up @@ -2318,7 +2317,18 @@ protected function _initInputField($field, $options = [])
if ($context->hasError($field)) {
$options = $this->addClass($options, $this->_config['errorClass']);
}
if (!empty($options['disabled'])) {
$isDisabled = false;
if (isset($options['disabled'])) {
$isDisabled = (
$options['disabled'] === true ||
$options['disabled'] === 'disabled' ||
(is_array($options['disabled']) &&
!empty($options['options']) &&
array_diff($options['options'], $options['disabled']) === array()
)
);
}
if ($isDisabled) {
$options['secure'] = self::SECURE_SKIP;
}
if ($options['secure'] === self::SECURE_SKIP) {
Expand Down
23 changes: 19 additions & 4 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -1544,10 +1544,13 @@ public function testFormSecuredInput()

$result = $this->Form->fields;
$expected = [
'ratio', 'population', 'published', 'other',
'stuff' => '',
'hidden' => '0',
'something'
'ratio',
'population',
'published',
'other',
'stuff' => '',
'hidden' => '0',
'something'
];
$this->assertEquals($expected, $result);

Expand Down Expand Up @@ -1645,6 +1648,18 @@ public function testFormSecuredRadio()
$this->Form->radio('Test.test', $options);
$expected = ['Test.test'];
$this->assertEquals($expected, $this->Form->fields);

$this->Form->radio('Test.all', $options, [
'disabled' => ['option1', 'option2']
]);
$expected = ['Test.test', 'Test.all' => ''];
$this->assertEquals($expected, $this->Form->fields);

$this->Form->radio('Test.some', $options, [
'disabled' => ['option1']
]);
$expected = ['Test.test', 'Test.all' => '', 'Test.some'];
$this->assertEquals($expected, $this->Form->fields);
}

/**
Expand Down

0 comments on commit 5114ffe

Please sign in to comment.