Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct placement of between on FormHelper radio and input #381

Merged
merged 1 commit into from
Dec 19, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
28 changes: 20 additions & 8 deletions lib/Cake/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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
Expand All @@ -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'];
}
Expand Down Expand Up @@ -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;
}
Expand Down