[limb-svn] r6699 - in 3.x/trunk/limb/macro: src/tags/form tests/cases/tags/form
svn at limb-project.com
svn at limb-project.com
Fri Jan 18 12:03:08 MSK 2008
Author: wiliam
Date: 2008-01-18 12:03:08 +0300 (Fri, 18 Jan 2008)
New Revision: 6699
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6699
Added:
3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroInputRadioTagTest.class.php
Modified:
3.x/trunk/limb/macro/src/tags/form/lmbMacroCheckableInputWidget.class.php
Log:
-- checkable element now can't be checked by default if it's value = null
Modified: 3.x/trunk/limb/macro/src/tags/form/lmbMacroCheckableInputWidget.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/form/lmbMacroCheckableInputWidget.class.php 2008-01-18 08:53:13 UTC (rev 6698)
+++ 3.x/trunk/limb/macro/src/tags/form/lmbMacroCheckableInputWidget.class.php 2008-01-18 09:03:08 UTC (rev 6699)
@@ -2,13 +2,13 @@
/*
* Limb PHP Framework
*
- * @link http://limb-project.com
+ * @link http://limb-project.com
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-
+
lmb_require('limb/macro/src/tags/form/lmbMacroFormElementWidget.class.php');
-
+
/**
* Represents an HTML input type="radio" and type="checkbox" tags
* @package macro
@@ -17,7 +17,7 @@
class lmbMacroCheckableInputWidget extends lmbMacroFormElementWidget
{
protected $skip_render = array('checked_value');
-
+
function getName()
{
$name = parent :: getName();
@@ -33,12 +33,12 @@
parent :: renderAttributes();
}
-
+
function getValue()
{
if($this->hasAttribute('checked_value'))
return $this->getAttribute('checked_value');
-
+
return $this->_getValueFromFormDatasource();
}
@@ -57,6 +57,8 @@
return true;
elseif($value && $value != $this->getAttribute('value'))
return false;
+ elseif(is_null($value))
+ return false;
elseif(!$value && $this->hasAttribute('value') && !$this->getAttribute('value'))
return true;
Added: 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroInputRadioTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroInputRadioTagTest.class.php (rev 0)
+++ 3.x/trunk/limb/macro/tests/cases/tags/form/lmbMacroInputRadioTagTest.class.php 2008-01-18 09:03:08 UTC (rev 6699)
@@ -0,0 +1,48 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+class lmbMacroInputRadioTagTest extends lmbBaseMacroTest
+{
+
+ function testIsChecked_If_ValueAttribute_IsEqual_To_FormDatasourceFieldValue()
+ {
+ $template = '{{form id="my_form"}}'.
+ '{{input type="radio" id="r1" name="my_input" value="foo"/}}'.
+ '{{input type="radio" id="r2" name="my_input" value="bar" checked="true" /}}'.
+ '{{/form}}';
+
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+ $page->set('form_my_form_datasource', array("my_input" => 'foo'));
+
+ $expected = '<form id="my_form">'.
+ '<input type="radio" id="r1" name="my_input" value="foo" checked="true" />'.
+ '<input type="radio" id="r2" name="my_input" value="bar" />'.
+ '</form>';
+ $this->assertEqual($page->render(), $expected);
+ }
+
+ function testRemoveCheckedIfNotChecked()
+ {
+ $template = '{{form id="my_form"}}'.
+ '{{input type="radio" id="r0" name="my_input" value="0"/}}'.
+ '{{input type="radio" id="r1" name="my_input" value="1" checked="true" /}}'.
+ '{{input type="radio" id="r2" name="my_input" value="2"/}}'.
+ '{{/form}}';
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+
+ $expected = '<form id="my_form">'.
+ '<input type="radio" id="r0" name="my_input" value="0" />'.
+ '<input type="radio" id="r1" name="my_input" value="1" checked="true" />'.
+ '<input type="radio" id="r2" name="my_input" value="2" />'.
+ '</form>';
+
+ $this->assertEqual($page->render(), $expected);
+ }
+}
+
More information about the limb-svn
mailing list