Skip to content
Browse files

Merge pull request #381 from shama/2.1

Correct placement of between on FormHelper radio and input
  • Loading branch information...
2 parents 0607437 + c93dab6 commit 28140f923bbbd32530173d4abf0b8213b8d96167 @markstory markstory committed Dec 18, 2011
Showing with 88 additions and 9 deletions.
  1. +68 −1 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +20 −8 lib/Cake/View/Helper/FormHelper.php
View
69 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -3356,7 +3356,6 @@ public function testRadio() {
);
$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 @@ public function testRadio() {
'/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 @@ public function testInputTemplate() {
'/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
28 lib/Cake/View/Helper/FormHelper.php
@@ -1070,6 +1070,10 @@ public function input($fieldName, $options = array()) {
$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 @@ public function checkbox($fieldName, $options = array()) {
* ### 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 @@ public function checkbox($fieldName, $options = array()) {
*/
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 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
));
}
}
- $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;
}

0 comments on commit 28140f9

Please sign in to comment.
Something went wrong with that request. Please try again.