Permalink
Browse files

fixed an issue with the form helper where the value zero would not di…

…splay (and a few small edits to pass lithium_qa)
  • Loading branch information...
1 parent 9511c05 commit d646c1f73f6a180276f36f8c627aa66f87483e66 @rmarscher rmarscher committed May 30, 2012
Showing with 30 additions and 7 deletions.
  1. +7 −3 template/helper/Form.php
  2. +23 −4 tests/cases/template/helper/FormTest.php
View
@@ -344,9 +344,9 @@ public function end() {
/**
* Returns the entity that the `Form` helper is currently bound to.
*
+ * @see lithium\template\helper\Form::$_binding
* @param string $name If specified, match this field name against the list of bindings
* @param string $key If $name specified, where to store relevant $_binding key
- * @see lithium\template\helper\Form::$_binding
* @return object Returns an object, usually an instance of `lithium\data\Entity`.
*/
public function binding($name = null) {
@@ -786,10 +786,14 @@ protected function _defaults($method, $name, $options) {
(!isset($options['value']) || $options['value'] === null) &&
$name && $value = $this->binding($name)->data
);
- if ($hasValue) {
+ $isZero = (isset($value) && ($value === 0 || $value === "0"));
+ if ($hasValue || $isZero) {
$options['value'] = $value;
}
- if (isset($options['default']) && empty($options['value'])) {
+ if (isset($options['value']) && !$isZero) {
+ $isZero = ($options['value'] === 0 || $options['value'] === "0");
+ }
+ if (isset($options['default']) && empty($options['value']) && !$isZero) {
$options['value'] = $options['default'];
}
unset($options['default']);
@@ -173,7 +173,9 @@ public function testFormDataBinding() {
'id' => '5',
'author_id' => '2',
'title' => 'This is a saved post',
- 'body' => 'This is the body of the saved post'
+ 'body' => 'This is the body of the saved post',
+ 'zeroInt' => 0,
+ 'zeroString' => "0"
)));
$result = $this->form->create($record);
@@ -187,6 +189,18 @@ public function testFormDataBinding() {
'value' => 'This is a saved post', 'id' => 'MockFormPostTitle'
)));
+
+ $result = $this->form->text('zeroInt');
+ $this->assertTags($result, array('input' => array(
+ 'type' => 'text', 'name' => 'zeroInt',
+ 'value' => '0', 'id' => 'MockFormPostZeroInt'
+ )));
+ $result = $this->form->text('zeroString');
+ $this->assertTags($result, array('input' => array(
+ 'type' => 'text', 'name' => 'zeroString',
+ 'value' => '0', 'id' => 'MockFormPostZeroString'
+ )));
+
$this->assertEqual('</form>', $this->form->end());
$this->assertTags($this->form->text('title'), array('input' => array(
@@ -382,12 +396,16 @@ public function testCheckboxGeneration() {
))
));
- $document = new Document(array('model' => $this->_model, 'data' => array('subdocument' => array('foo' => true))));
+ $document = new Document(array('model' => $this->_model, 'data' =>
+ array('subdocument' => array('foo' => true))
+ ));
$this->form->create($document);
$result = $this->form->checkbox('subdocument.foo');
$this->assertTags($result, array(
- array('input' => array('type' => 'hidden', 'value' => '', 'name' => 'subdocument[foo]')),
+ array('input' => array(
+ 'type' => 'hidden', 'value' => '', 'name' => 'subdocument[foo]')
+ ),
array('input' => array(
'type' => 'checkbox', 'value' => '1', 'name' => 'subdocument[foo]',
'checked' => 'checked', 'id' => 'MockFormPostSubdocumentFoo'
@@ -614,7 +632,8 @@ public function testSelectGeneration() {
/**
* When trying to determine which option of a select box should be selected, we should be
- * int/string agnostic because it all looks the same in HTML.
+ * integer/string agnostic because it all looks the same in HTML.
+ *
*/
public function testSelectTypeAgnosticism() {
$taglist = array(

0 comments on commit d646c1f

Please sign in to comment.