mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Merge pull request #381 from shama/2.1
Correct placement of between on FormHelper radio and input
This commit is contained in:
commit
28140f923b
2 changed files with 88 additions and 9 deletions
|
@ -3356,7 +3356,6 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
|
||||||
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]'));
|
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'fieldset' => array(),
|
'fieldset' => array(),
|
||||||
|
@ -3375,6 +3374,39 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'/fieldset'
|
'/fieldset'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Form->radio(
|
||||||
|
'Model.field',
|
||||||
|
array('option A', 'option B'),
|
||||||
|
array('between' => 'I am between')
|
||||||
|
);
|
||||||
|
$expected = array(
|
||||||
|
'fieldset' => array(),
|
||||||
|
'legend' => array(),
|
||||||
|
'Field',
|
||||||
|
'/legend',
|
||||||
|
'I am between',
|
||||||
|
'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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7568,6 +7600,41 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'/div'
|
'/div'
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->Form->input('Contact.method', array(
|
||||||
|
'type' => 'radio',
|
||||||
|
'options' => array('email' => 'Email', 'pigeon' => 'Pigeon'),
|
||||||
|
'between' => 'I am between',
|
||||||
|
));
|
||||||
|
$expected = array(
|
||||||
|
'div' => array('class' => 'input radio'),
|
||||||
|
'fieldset' => array(),
|
||||||
|
'legend' => array(),
|
||||||
|
'Method',
|
||||||
|
'/legend',
|
||||||
|
'I am between',
|
||||||
|
'input' => array(
|
||||||
|
'type' => 'hidden', 'name' => 'data[Contact][method]',
|
||||||
|
'value' => '', 'id' => 'ContactMethod_'
|
||||||
|
),
|
||||||
|
array('input' => array(
|
||||||
|
'type' => 'radio', 'name' => 'data[Contact][method]',
|
||||||
|
'value' => 'email', 'id' => 'ContactMethodEmail'
|
||||||
|
)),
|
||||||
|
array('label' => array('for' => 'ContactMethodEmail')),
|
||||||
|
'Email',
|
||||||
|
'/label',
|
||||||
|
array('input' => array(
|
||||||
|
'type' => 'radio', 'name' => 'data[Contact][method]',
|
||||||
|
'value' => 'pigeon', 'id' => 'ContactMethodPigeon'
|
||||||
|
)),
|
||||||
|
array('label' => array('for' => 'ContactMethodPigeon')),
|
||||||
|
'Pigeon',
|
||||||
|
'/label',
|
||||||
|
'/fieldset',
|
||||||
|
'/div',
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1070,6 +1070,10 @@ class FormHelper extends AppHelper {
|
||||||
$format = $format ? $format : array('before', 'input', 'between', 'label', 'after', 'error');
|
$format = $format ? $format : array('before', 'input', 'between', 'label', 'after', 'error');
|
||||||
break;
|
break;
|
||||||
case 'radio':
|
case 'radio':
|
||||||
|
if (isset($out['between'])) {
|
||||||
|
$options['between'] = $out['between'];
|
||||||
|
$out['between'] = null;
|
||||||
|
}
|
||||||
$input = $this->radio($fieldName, $radioOptions, $options);
|
$input = $this->radio($fieldName, $radioOptions, $options);
|
||||||
break;
|
break;
|
||||||
case 'file':
|
case 'file':
|
||||||
|
@ -1248,6 +1252,7 @@ class FormHelper extends AppHelper {
|
||||||
* ### Attributes:
|
* ### Attributes:
|
||||||
*
|
*
|
||||||
* - `separator` - define the string in between the radio buttons
|
* - `separator` - define the string in between the radio buttons
|
||||||
|
* - `between` - the string between legend and input set
|
||||||
* - `legend` - control whether or not the widget set has a fieldset & legend
|
* - `legend` - control whether or not the widget set has a fieldset & legend
|
||||||
* - `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
|
||||||
|
@ -1262,34 +1267,41 @@ 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;
|
|
||||||
$disabled = array();
|
|
||||||
|
|
||||||
|
$legend = false;
|
||||||
if (isset($attributes['legend'])) {
|
if (isset($attributes['legend'])) {
|
||||||
$legend = $attributes['legend'];
|
$legend = $attributes['legend'];
|
||||||
unset($attributes['legend']);
|
unset($attributes['legend']);
|
||||||
} elseif (count($options) > 1) {
|
} elseif (count($options) > 1) {
|
||||||
$legend = __(Inflector::humanize($this->field()));
|
$legend = __(Inflector::humanize($this->field()));
|
||||||
}
|
}
|
||||||
$label = true;
|
|
||||||
|
|
||||||
|
$label = true;
|
||||||
if (isset($attributes['label'])) {
|
if (isset($attributes['label'])) {
|
||||||
$label = $attributes['label'];
|
$label = $attributes['label'];
|
||||||
unset($attributes['label']);
|
unset($attributes['label']);
|
||||||
}
|
}
|
||||||
$inbetween = null;
|
|
||||||
|
|
||||||
|
$separator = null;
|
||||||
if (isset($attributes['separator'])) {
|
if (isset($attributes['separator'])) {
|
||||||
$inbetween = $attributes['separator'];
|
$separator = $attributes['separator'];
|
||||||
unset($attributes['separator']);
|
unset($attributes['separator']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$between = null;
|
||||||
|
if (isset($attributes['between'])) {
|
||||||
|
$between = $attributes['between'];
|
||||||
|
unset($attributes['between']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = null;
|
||||||
if (isset($attributes['value'])) {
|
if (isset($attributes['value'])) {
|
||||||
$value = $attributes['value'];
|
$value = $attributes['value'];
|
||||||
} else {
|
} else {
|
||||||
$value = $this->value($fieldName);
|
$value = $this->value($fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$disabled = array();
|
||||||
if (isset($attributes['disabled'])) {
|
if (isset($attributes['disabled'])) {
|
||||||
$disabled = $attributes['disabled'];
|
$disabled = $attributes['disabled'];
|
||||||
}
|
}
|
||||||
|
@ -1330,10 +1342,10 @@ class FormHelper extends AppHelper {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$out = $hidden . implode($inbetween, $out);
|
$out = $hidden . implode($separator, $out);
|
||||||
|
|
||||||
if ($legend) {
|
if ($legend) {
|
||||||
$out = $this->Html->useTag('fieldset', '', $this->Html->useTag('legend', $legend) . $out);
|
$out = $this->Html->useTag('fieldset', '', $this->Html->useTag('legend', $legend) . $between . $out);
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue