Permalink
Browse files

radio input no longer sets 0 values as checked when data isset as emp…

…ty string, fixes #2209
  • Loading branch information...
ceeram committed Nov 4, 2011
1 parent e21721a commit f760b54bd9931f23b1bc57d1ee576f6f59c8d930
Showing with 21 additions and 1 deletion.
  1. +1 −1 cake/libs/view/helpers/form.php
  2. +20 −0 cake/tests/cases/libs/view/helpers/form.test.php
@@ -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(
@@ -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'),

0 comments on commit f760b54

Please sign in to comment.