Skip to content

Commit

Permalink
radio input no longer sets 0 values as checked when data isset as emp…
Browse files Browse the repository at this point in the history
…ty string, fixes #2209
  • Loading branch information
ceeram committed Nov 4, 2011
1 parent e21721a commit f760b54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ function radio($fieldName, $options = array(), $attributes = array()) {
foreach ($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue);

if (isset($value) && $optValue == $value) {
if (isset($value) && $value !== '' && $optValue == $value) {
$optionsHere['checked'] = 'checked';
}
$parsedOptions = $this->_parseAttributes(
Expand Down
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2951,6 +2951,26 @@ function testRadio() {
);
$this->assertTags($result, $expected);

$this->Form->data = array('Model' => array('field' => ''));
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'));
$expected = array(
'fieldset' => array(),
'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' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'Yes',
'/label',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
array('label' => array('for' => 'ModelField0')),
'No',
'/label',
'/fieldset'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
$expected = array(
'div' => array('class' => 'input radio'),
Expand Down

0 comments on commit f760b54

Please sign in to comment.