Skip to content
Browse files

Adding a default value for checkbox field

  • Loading branch information...
1 parent cdba6ce commit c7ecf93443e3dabf38e1c501874c8e7ef3caf499 @chdemko committed Feb 23, 2012
View
5 libraries/joomla/form/fields/checkbox.php
@@ -43,12 +43,13 @@ protected function getInput()
// Initialize some field attributes.
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
- $checked = ((string) $this->element['value'] == $this->value) ? ' checked="checked"' : '';
+ $value = $this->element['value'] ? (string) $this->element['value'] : '1';
+ $checked = ($value == $this->value) ? ' checked="checked"' : '';
// Initialize JavaScript field attributes.
$onclick = $this->element['onclick'] ? ' onclick="' . (string) $this->element['onclick'] . '"' : '';
return '<input type="checkbox" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
- . htmlspecialchars((string) $this->element['value'], ENT_COMPAT, 'UTF-8') . '"' . $class . $checked . $disabled . $onclick . '/>';
+ . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $class . $checked . $disabled . $onclick . ' />';
}
}
View
8 tests/suite/joomla/form/fields/JFormFieldCheckboxTest.php
@@ -41,7 +41,7 @@ public function testGetInput()
$form = new JFormInspector('form1');
$this->assertThat(
- $form->load('<form><field name="checkbox" type="checkbox"><option value="all">All</option><option value="none">None</option><option value="something">Something</option><item value="fake">Fake</item></field></form>'),
+ $form->load('<form><field name="checkbox" type="checkbox" /></form>'),
$this->isTrue(),
'Line:'.__LINE__.' XML string should load successfully.'
);
@@ -59,5 +59,11 @@ public function testGetInput()
$this->greaterThan(0),
'Line:'.__LINE__.' The getInput method should return something without error.'
);
+
+ $this->assertThat(
+ $field->input,
+ $this->equalTo('<input type="checkbox" name="checkbox" id="checkbox" value="1" />'),
+ 'Line:'.__LINE__.' The getInput method should return something without error.'
+ );
}
}

0 comments on commit c7ecf93

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