mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Applying patch from 'NaMB' to add disabled support to FormHelper::radio(). Test cases added as well. Fixes #1459
This commit is contained in:
parent
30a9543a65
commit
b9ec7da21d
2 changed files with 38 additions and 0 deletions
|
@ -1039,6 +1039,7 @@ class FormHelper extends AppHelper {
|
||||||
public function radio($fieldName, $options = array(), $attributes = array()) {
|
public function radio($fieldName, $options = array(), $attributes = array()) {
|
||||||
$attributes = $this->_initInputField($fieldName, $attributes);
|
$attributes = $this->_initInputField($fieldName, $attributes);
|
||||||
$legend = false;
|
$legend = false;
|
||||||
|
$disabled = array();
|
||||||
|
|
||||||
if (isset($attributes['legend'])) {
|
if (isset($attributes['legend'])) {
|
||||||
$legend = $attributes['legend'];
|
$legend = $attributes['legend'];
|
||||||
|
@ -1064,6 +1065,11 @@ class FormHelper extends AppHelper {
|
||||||
} else {
|
} else {
|
||||||
$value = $this->value($fieldName);
|
$value = $this->value($fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($attributes['disabled'])) {
|
||||||
|
$disabled = $attributes['disabled'];
|
||||||
|
}
|
||||||
|
|
||||||
$out = array();
|
$out = array();
|
||||||
|
|
||||||
$hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true;
|
$hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true;
|
||||||
|
@ -1075,6 +1081,9 @@ class FormHelper extends AppHelper {
|
||||||
if (isset($value) && $optValue == $value) {
|
if (isset($value) && $optValue == $value) {
|
||||||
$optionsHere['checked'] = 'checked';
|
$optionsHere['checked'] = 'checked';
|
||||||
}
|
}
|
||||||
|
if (!empty($disabled) && in_array($optValue, $disabled)) {
|
||||||
|
$optionsHere['disabled'] = true;
|
||||||
|
}
|
||||||
$tagName = Inflector::camelize(
|
$tagName = Inflector::camelize(
|
||||||
$attributes['id'] . '_' . Inflector::slug($optValue)
|
$attributes['id'] . '_' . Inflector::slug($optValue)
|
||||||
);
|
);
|
||||||
|
|
|
@ -3012,6 +3012,35 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test disabled radio options
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testRadioDisabled() {
|
||||||
|
$result = $this->Form->radio(
|
||||||
|
'Model.field',
|
||||||
|
array('option A', 'option B'),
|
||||||
|
array('disabled' => array('option A'), 'value' => 'option A')
|
||||||
|
);
|
||||||
|
$expected = array(
|
||||||
|
'fieldset' => array(),
|
||||||
|
'legend' => array(),
|
||||||
|
'Field',
|
||||||
|
'/legend',
|
||||||
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
|
||||||
|
array('label' => array('for' => 'ModelField0')),
|
||||||
|
'option A',
|
||||||
|
'/label',
|
||||||
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
||||||
|
array('label' => array('for' => 'ModelField1')),
|
||||||
|
'option B',
|
||||||
|
'/label',
|
||||||
|
'/fieldset'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test disabling the hidden input for radio buttons
|
* test disabling the hidden input for radio buttons
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue