mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #8848 from xhs345/2.x
Add attribute 'fieldset' to Form->radio
This commit is contained in:
commit
1a7e8c51e7
2 changed files with 38 additions and 6 deletions
|
@ -3914,6 +3914,25 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('fieldset' => 'classy-stuff'));
|
||||||
|
$expected = array(
|
||||||
|
'fieldset' => array('class' => 'classy-stuff'),
|
||||||
|
'legend' => array(),
|
||||||
|
'Field',
|
||||||
|
'/legend',
|
||||||
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
||||||
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
||||||
|
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);
|
||||||
|
|
||||||
$result = $this->Form->radio(
|
$result = $this->Form->radio(
|
||||||
'Employee.gender',
|
'Employee.gender',
|
||||||
array('male' => 'Male', 'female' => 'Female'),
|
array('male' => 'Male', 'female' => 'Female'),
|
||||||
|
|
|
@ -932,11 +932,15 @@ class FormHelper extends AppHelper {
|
||||||
|
|
||||||
if (isset($options['legend'])) {
|
if (isset($options['legend'])) {
|
||||||
$legend = $options['legend'];
|
$legend = $options['legend'];
|
||||||
|
unset($options['legend']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['fieldset'])) {
|
if (isset($options['fieldset'])) {
|
||||||
$fieldset = $options['fieldset'];
|
$fieldset = $options['fieldset'];
|
||||||
|
unset($options['fieldset']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (empty($fields)) {
|
if (empty($fields)) {
|
||||||
$fields = $modelFields;
|
$fields = $modelFields;
|
||||||
}
|
}
|
||||||
|
@ -971,11 +975,11 @@ class FormHelper extends AppHelper {
|
||||||
$out .= $this->input($name, $options);
|
$out .= $this->input($name, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string($fieldset)) {
|
if (is_string($fieldset)) {
|
||||||
$fieldsetClass = sprintf(' class="%s"', $fieldset);
|
$fieldsetClass = array('class' => $fieldset);
|
||||||
} else {
|
} else {
|
||||||
$fieldsetClass = '';
|
$fieldsetClass = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fieldset) {
|
if ($fieldset) {
|
||||||
if ($legend) {
|
if ($legend) {
|
||||||
|
@ -1510,6 +1514,7 @@ class FormHelper extends AppHelper {
|
||||||
* - `between` - the string between legend and input set or array of strings to insert
|
* - `between` - the string between legend and input set or array of strings to insert
|
||||||
* strings between each input block
|
* strings between each input block
|
||||||
* - `legend` - control whether or not the widget set has a fieldset & legend
|
* - `legend` - control whether or not the widget set has a fieldset & legend
|
||||||
|
* - `fieldset` - sets the class of the fieldset. Fieldset is only generated if legend attribute is provided
|
||||||
* - `value` - indicate a value that is should be checked
|
* - `value` - indicate a value that is should be checked
|
||||||
* - `label` - boolean to indicate whether or not labels for widgets show be displayed
|
* - `label` - boolean to indicate whether or not labels for widgets show be displayed
|
||||||
* - `hiddenField` - boolean to indicate if you want the results of radio() to include
|
* - `hiddenField` - boolean to indicate if you want the results of radio() to include
|
||||||
|
@ -1544,6 +1549,12 @@ class FormHelper extends AppHelper {
|
||||||
$legend = __(Inflector::humanize($this->field()));
|
$legend = __(Inflector::humanize($this->field()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$fieldsetAttrs = '';
|
||||||
|
if (isset($attributes['fieldset'])) {
|
||||||
|
$fieldsetAttrs = array('class' => $attributes['fieldset']);
|
||||||
|
unset($attributes['fieldset']);
|
||||||
|
}
|
||||||
|
|
||||||
$label = true;
|
$label = true;
|
||||||
if (isset($attributes['label'])) {
|
if (isset($attributes['label'])) {
|
||||||
$label = $attributes['label'];
|
$label = $attributes['label'];
|
||||||
|
@ -1637,8 +1648,10 @@ class FormHelper extends AppHelper {
|
||||||
if (is_array($between)) {
|
if (is_array($between)) {
|
||||||
$between = '';
|
$between = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($legend) {
|
if ($legend) {
|
||||||
$out = $this->Html->useTag('fieldset', '', $this->Html->useTag('legend', $legend) . $between . $out);
|
$out = $this->Html->useTag('legend', $legend) . $between . $out;
|
||||||
|
$out = $this->Html->useTag('fieldset', $fieldsetAttrs, $out);
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue