summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorctrlaltca@gmail.com <>2012-02-05 17:00:00 +0000
committerctrlaltca@gmail.com <>2012-02-05 17:00:00 +0000
commit4a8bd53f85b2dc0bcddd415873ce4ab49e1e099c (patch)
treec971ba1fcc4b414f2a4148b455ce249088cd5525 /framework
parent871b91b471434aef56e421888bae1146dd74c990 (diff)
Make validators' FocusOnError play nice with TCheckBoxList and TRadioButtonList
Diffstat (limited to 'framework')
-rw-r--r--framework/TService.php164
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php13
-rw-r--r--framework/Web/UI/WebControls/TRadioButtonList.php200
3 files changed, 194 insertions, 183 deletions
diff --git a/framework/TService.php b/framework/TService.php
index 9d1e6f84..b4c2b529 100644
--- a/framework/TService.php
+++ b/framework/TService.php
@@ -1,83 +1,83 @@
-<?php
-/**
- * TService class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TService class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2011 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System
- */
-
-/**
- * TService class.
- *
- * TService implements the basic methods required by IService and may be
- * used as the basic class for application services.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System
- * @since 3.0
- */
-abstract class TService extends TApplicationComponent implements IService
-{
- /**
- * @var string service id
- */
- private $_id;
- /**
- * @var boolean whether the service is enabled
- */
- private $_enabled=true;
-
- /**
- * Initializes the service and attaches {@link run} to the RunService event of application.
- * This method is required by IService and is invoked by application.
- * @param TXmlElement module configuration
- */
- public function init($config)
- {
- }
-
- /**
- * @return string id of this service
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * @param string id of this service
- */
- public function setID($value)
- {
- $this->_id=$value;
- }
-
- /**
- * @return boolean whether the service is enabled
- */
- public function getEnabled()
- {
- return $this->_enabled;
- }
-
- /**
- * @param boolean whether the service is enabled
- */
- public function setEnabled($value)
- {
- $this->_enabled=TPropertyValue::ensureBoolean($value);
- }
-
- /**
- * Runs the service.
- */
- public function run()
- {
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System
+ */
+
+/**
+ * TService class.
+ *
+ * TService implements the basic methods required by IService and may be
+ * used as the basic class for application services.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System
+ * @since 3.0
+ */
+abstract class TService extends TApplicationComponent implements IService
+{
+ /**
+ * @var string service id
+ */
+ private $_id;
+ /**
+ * @var boolean whether the service is enabled
+ */
+ private $_enabled=true;
+
+ /**
+ * Initializes the service and attaches {@link run} to the RunService event of application.
+ * This method is required by IService and is invoked by application.
+ * @param TXmlElement module configuration
+ */
+ public function init($config)
+ {
+ }
+
+ /**
+ * @return string id of this service
+ */
+ public function getID()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * @param string id of this service
+ */
+ public function setID($value)
+ {
+ $this->_id=$value;
+ }
+
+ /**
+ * @return boolean whether the service is enabled
+ */
+ public function getEnabled()
+ {
+ return $this->_enabled;
+ }
+
+ /**
+ * @param boolean whether the service is enabled
+ */
+ public function setEnabled($value)
+ {
+ $this->_enabled=TPropertyValue::ensureBoolean($value);
+ }
+
+ /**
+ * Runs the service.
+ */
+ public function run()
+ {
+ }
+}
+
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php
index 6e4e8f71..30320c5f 100644
--- a/framework/Web/UI/WebControls/TBaseValidator.php
+++ b/framework/Web/UI/WebControls/TBaseValidator.php
@@ -416,7 +416,18 @@ abstract class TBaseValidator extends TLabel implements IValidator
public function getFocusElementID()
{
if(($id=$this->getViewState('FocusElementID',''))==='')
- $id=$this->getValidationTarget()->getClientID();
+ {
+ $target=$this->getValidationTarget();
+ /* Workaround: TCheckBoxList and TRadioButtonList nests the actual
+ * inputs inside a table; we ensure the first input gets focused
+ */
+ if($target instanceof TCheckBoxList && $target->getItemCount()>0)
+ {
+ $id=$target->getClientID().'_c0';
+ } else {
+ $id=$target->getClientID();
+ }
+ }
return $id;
}
diff --git a/framework/Web/UI/WebControls/TRadioButtonList.php b/framework/Web/UI/WebControls/TRadioButtonList.php
index 88dff7dd..88d98881 100644
--- a/framework/Web/UI/WebControls/TRadioButtonList.php
+++ b/framework/Web/UI/WebControls/TRadioButtonList.php
@@ -1,101 +1,101 @@
-<?php
-/**
- * TRadioButtonList class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
+<?php
+/**
+ * TRadioButtonList class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2011 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Web.UI.WebControls
- */
-
-/**
- * Includes TRadioButton class
- */
-Prado::using('System.Web.UI.WebControls.TRadioButton');
-/**
- * Includes TCheckBoxList class
- */
-Prado::using('System.Web.UI.WebControls.TCheckBoxList');
-
-/**
- * TRadioButtonList class
- *
- * TRadioButtonList displays a list of radiobuttons on a Web page.
- *
- * TRadioButtonList inherits all properties and events of {@link TCheckBoxList}.
- * Each TRadioButtonList displays one group of radiobuttons, i.e., at most
- * one radiobutton can be selected at a time.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id$
- * @package System.Web.UI.WebControls
- * @since 3.0
- */
-class TRadioButtonList extends TCheckBoxList
-{
- /**
- * @return boolean whether this control supports multiple selection. Always false for radiobutton list.
- */
- protected function getIsMultiSelect()
- {
- return false;
- }
-
- /**
- * Creates a control used for repetition (used as a template).
- * @return TControl the control to be repeated
- */
- protected function createRepeatedControl()
- {
- return new TRadioButton;
- }
-
- /**
- * Loads user input data.
- * This method is primarly used by framework developers.
- * @param string the key that can be used to retrieve data from the input data collection
- * @param array the input data collection
- * @return boolean whether the data of the control has been changed
- */
- public function loadPostData($key,$values)
- {
- $value=isset($values[$key])?$values[$key]:'';
- $oldSelection=$this->getSelectedIndex();
- $this->ensureDataBound();
- foreach($this->getItems() as $index=>$item)
- {
- if($item->getEnabled() && $item->getValue()===$value)
- {
- if($index===$oldSelection)
- return false;
- else
- {
- $this->setSelectedIndex($index);
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * @throws TNotSupportedException if this method is invoked
- */
- public function setSelectedIndices($indices)
- {
- throw new TNotSupportedException('radiobuttonlist_selectedindices_unsupported');
- }
-
- /**
- * Gets the name of the javascript class responsible for performing postback for this control.
- * This method overrides the parent implementation.
- * @return string the javascript class name
- */
- protected function getClientClassName()
- {
- return 'Prado.WebUI.TRadioButtonList';
- }
-}
-
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * Includes TRadioButton class
+ */
+Prado::using('System.Web.UI.WebControls.TRadioButton');
+/**
+ * Includes TCheckBoxList class
+ */
+Prado::using('System.Web.UI.WebControls.TCheckBoxList');
+
+/**
+ * TRadioButtonList class
+ *
+ * TRadioButtonList displays a list of radiobuttons on a Web page.
+ *
+ * TRadioButtonList inherits all properties and events of {@link TCheckBoxList}.
+ * Each TRadioButtonList displays one group of radiobuttons, i.e., at most
+ * one radiobutton can be selected at a time.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TRadioButtonList extends TCheckBoxList
+{
+ /**
+ * @return boolean whether this control supports multiple selection. Always false for radiobutton list.
+ */
+ protected function getIsMultiSelect()
+ {
+ return false;
+ }
+
+ /**
+ * Creates a control used for repetition (used as a template).
+ * @return TControl the control to be repeated
+ */
+ protected function createRepeatedControl()
+ {
+ return new TRadioButton;
+ }
+
+ /**
+ * Loads user input data.
+ * This method is primarly used by framework developers.
+ * @param string the key that can be used to retrieve data from the input data collection
+ * @param array the input data collection
+ * @return boolean whether the data of the control has been changed
+ */
+ public function loadPostData($key,$values)
+ {
+ $value=isset($values[$key])?$values[$key]:'';
+ $oldSelection=$this->getSelectedIndex();
+ $this->ensureDataBound();
+ foreach($this->getItems() as $index=>$item)
+ {
+ if($item->getEnabled() && $item->getValue()===$value)
+ {
+ if($index===$oldSelection)
+ return false;
+ else
+ {
+ $this->setSelectedIndex($index);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @throws TNotSupportedException if this method is invoked
+ */
+ public function setSelectedIndices($indices)
+ {
+ throw new TNotSupportedException('radiobuttonlist_selectedindices_unsupported');
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName()
+ {
+ return 'Prado.WebUI.TRadioButtonList';
+ }
+}
+