Merge pull request #381 from shama/2.1

Correct placement of between on FormHelper radio and input
This commit is contained in:
Mark Story 2011-12-18 19:35:49 -08:00
commit 28140f923b
2 changed files with 88 additions and 9 deletions

View file

@ -3356,7 +3356,6 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]'));
$expected = array(
'fieldset' => array(),
@ -3375,6 +3374,39 @@ class FormHelperTest extends CakeTestCase {
'/fieldset'
);
$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'
);
$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);
}
/**

View file

@ -1070,6 +1070,10 @@ class FormHelper extends AppHelper {
$format = $format ? $format : array('before', 'input', 'between', 'label', 'after', 'error');
break;
case 'radio':
if (isset($out['between'])) {
$options['between'] = $out['between'];
$out['between'] = null;
}
$input = $this->radio($fieldName, $radioOptions, $options);
break;
case 'file':
@ -1248,6 +1252,7 @@ class FormHelper extends AppHelper {
* ### Attributes:
*
* - `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
* - `value` - indicate a value that is should be checked
* - `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()) {
$attributes = $this->_initInputField($fieldName, $attributes);
$legend = false;
$disabled = array();
$legend = false;
if (isset($attributes['legend'])) {
$legend = $attributes['legend'];
unset($attributes['legend']);
} elseif (count($options) > 1) {
$legend = __(Inflector::humanize($this->field()));
}
$label = true;
$label = true;
if (isset($attributes['label'])) {
$label = $attributes['label'];
unset($attributes['label']);
}
$inbetween = null;
$separator = null;
if (isset($attributes['separator'])) {
$inbetween = $attributes['separator'];
$separator = $attributes['separator'];
unset($attributes['separator']);
}
$between = null;
if (isset($attributes['between'])) {
$between = $attributes['between'];
unset($attributes['between']);
}
$value = null;
if (isset($attributes['value'])) {
$value = $attributes['value'];
} else {
$value = $this->value($fieldName);
$value = $this->value($fieldName);
}
$disabled = array();
if (isset($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) {
$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;
}