summaryrefslogtreecommitdiff
path: root/framework/Web/UI
diff options
context:
space:
mode:
authorctrlaltca@gmail.com <>2011-10-21 09:06:19 +0000
committerctrlaltca@gmail.com <>2011-10-21 09:06:19 +0000
commitad678bcd067deafcaa9984b179471fd980465cd8 (patch)
treec59ae3e5c0ad9df602872ab00ab3d90284526952 /framework/Web/UI
parent22471c977d4edc4ddfe63abe23928d03e659f045 (diff)
fixes #368 + documentation-only addition to TDropDownList, other changes are due to line ending
Diffstat (limited to 'framework/Web/UI')
-rw-r--r--framework/Web/UI/ActiveControls/TActiveListControlAdapter.php25
-rw-r--r--framework/Web/UI/WebControls/TDropDownList.php44
2 files changed, 49 insertions, 20 deletions
diff --git a/framework/Web/UI/ActiveControls/TActiveListControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveListControlAdapter.php
index 30f09d78..66e3e8d1 100644
--- a/framework/Web/UI/ActiveControls/TActiveListControlAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActiveListControlAdapter.php
@@ -46,6 +46,15 @@ class TActiveListControlAdapter extends TActiveControlAdapter implements IListCo
if($this->canUpdateClientSide())
{
$this->updateListItems();
+ // if a prompt is set, we mimic the postback behaviour of not counting it
+ // in the index. We assume the prompt is _always_ the first item (Issue #368)
+ $promptValue=$this->getControl()->getPromptValue();
+ if($promptValue==='')
+ $promptValue=$this->getControl()->getPromptText();
+ if($promptValue!=='')
+ $index++;
+
+ if($index >= 0 && $index <= $this->getControl()->getItemCount())
$this->getPage()->getCallbackClient()->select(
$this->getControl(), 'Index', $index);
}
@@ -61,10 +70,17 @@ class TActiveListControlAdapter extends TActiveControlAdapter implements IListCo
{
$this->updateListItems();
$n = $this->getControl()->getItemCount();
+
+ $promptValue=$this->getControl()->getPromptValue();
+ if($promptValue==='')
+ $promptValue=$this->getControl()->getPromptText();
+
$list = array();
foreach($indices as $index)
{
$index = intval($index);
+ if($promptValue!=='')
+ $index++;
if($index >= 0 && $index <= $n)
$list[] = $index;
}
@@ -114,7 +130,14 @@ class TActiveListControlAdapter extends TActiveControlAdapter implements IListCo
if($this->canUpdateClientSide())
{
$this->updateListItems();
- $this->getPage()->getCallbackClient()->select($this->getControl(), 'Clear');
+ if($this->getControl() instanceof TActiveDropDownList)
+ {
+ // clearing a TActiveDropDownList's selection actually doesn't select the first item;
+ // we mimic the postback behaviour selecting it (Issue #368)
+ $this->getPage()->getCallbackClient()->select($this->getControl(), 'Index', 0);
+ } else {
+ $this->getPage()->getCallbackClient()->select($this->getControl(), 'Clear');
+ }
}
}
diff --git a/framework/Web/UI/WebControls/TDropDownList.php b/framework/Web/UI/WebControls/TDropDownList.php
index abd1bca5..f66daaf7 100644
--- a/framework/Web/UI/WebControls/TDropDownList.php
+++ b/framework/Web/UI/WebControls/TDropDownList.php
@@ -4,7 +4,7 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2011 PradoSoft
+ * @copyright Copyright &copy; 2005-2011 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web.UI.WebControls
@@ -32,6 +32,12 @@ Prado::using('System.Web.UI.WebControls.TListControl');
* displayed as the first list item by specifying either {@link setPromptText PromptText} or
* {@link setPromptValue PromptValue}, or both. Choosing the prompt item will unselect the TDropDownList.
*
+ * When a prompt item is set, its index in the list is set to -1. So, the {@link getSelectedIndex SelectedIndex}
+ * property is not affected by a prompt item: the items list will still be zero-based.
+ *
+ * The {@link clearSelection clearSelection} method will select the prompt item if existing, otherway the first
+ * available item in the dropdown list will be selected.
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package System.Web.UI.WebControls
@@ -40,7 +46,7 @@ Prado::using('System.Web.UI.WebControls.TListControl');
class TDropDownList extends TListControl implements IPostBackDataHandler, IValidatable
{
private $_dataChanged=false;
- private $_isValid=true;
+ private $_isValid=true;
/**
* Adds attributes to renderer.
@@ -128,21 +134,21 @@ class TDropDownList extends TListControl implements IPostBackDataHandler, IValid
{
return $this->getSelectedValue();
}
-
- /**
- * Returns true if this control validated successfully.
- * Defaults to true.
- * @return bool wether this control validated successfully.
- */
- public function getIsValid()
- {
- return $this->_isValid;
- }
- /**
- * @param bool wether this control is valid.
- */
- public function setIsValid($value)
- {
- $this->_isValid=TPropertyValue::ensureBoolean($value);
- }
+
+ /**
+ * Returns true if this control validated successfully.
+ * Defaults to true.
+ * @return bool wether this control validated successfully.
+ */
+ public function getIsValid()
+ {
+ return $this->_isValid;
+ }
+ /**
+ * @param bool wether this control is valid.
+ */
+ public function setIsValid($value)
+ {
+ $this->_isValid=TPropertyValue::ensureBoolean($value);
+ }
}