summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls
diff options
context:
space:
mode:
authorxue <>2007-09-28 01:50:32 +0000
committerxue <>2007-09-28 01:50:32 +0000
commit95cc364ff7afdf2b70c1332e6980141a9645b304 (patch)
tree99fc758386e8caf2a3b5e9edcceeb13140524a6c /framework/Web/UI/WebControls
parentbf52fb00087ceb045f50920e031538fbef9002a1 (diff)
Added support to prompt list item.
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r--framework/Web/UI/WebControls/TDropDownList.php4
-rw-r--r--framework/Web/UI/WebControls/TListControl.php63
2 files changed, 67 insertions, 0 deletions
diff --git a/framework/Web/UI/WebControls/TDropDownList.php b/framework/Web/UI/WebControls/TDropDownList.php
index 3270ad16..883073c5 100644
--- a/framework/Web/UI/WebControls/TDropDownList.php
+++ b/framework/Web/UI/WebControls/TDropDownList.php
@@ -28,6 +28,10 @@ Prado::using('System.Web.UI.WebControls.TListControl');
* // or <com:TListItem Attributes.Group="Group Name" .../> in template
* </code>
*
+ * Since v3.1.1, TDropDownList starts to support prompt text. That is, a prompt item can be
+ * displayed as the first list item by specifying {@link setPromptText PromptText}. Choosing
+ * the prompt item will unselect the TDropDownList.
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package System.Web.UI.WebControls
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index bb51934c..6e478550 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -704,6 +704,44 @@ abstract class TListControl extends TDataBoundControl implements IDataRenderer
}
/**
+ * @return string the prompt text which is to be displayed as the first list item. Defaults to empty, meaning no prompt.
+ * @since 3.1.1
+ */
+ public function getPromptText()
+ {
+ return $this->getViewState('PromptText','');
+ }
+
+ /**
+ * @param string the prompt text which is to be displayed as the first list item. If empty, {@link getPromptValue PromptValue} will be displayed.
+ * @since 3.1.1
+ */
+ public function setPromptText($value)
+ {
+ $this->setViewState('PromptText',$value,'');
+ }
+
+ /**
+ * @return string the prompt selection value. Defaults to empty, meaning no prompt.
+ * @see getPromptText
+ * @since 3.1.1
+ */
+ public function getPromptValue()
+ {
+ return $this->getViewState('PromptValue','');
+ }
+
+ /**
+ * @param string the prompt selection value. If empty, {@link getPromptText PromptText} will be used as the value.
+ * @see setPromptText
+ * @since 3.1.1
+ */
+ public function setPromptValue($value)
+ {
+ $this->setViewState('PromptValue',(string)$value,'');
+ }
+
+ /**
* Raises OnSelectedIndexChanged event when selection is changed.
* This method is invoked when the list control has its selection changed
* by end-users.
@@ -727,6 +765,29 @@ abstract class TListControl extends TDataBoundControl implements IDataRenderer
}
/**
+ * Renders the prompt text, if any.
+ * @param THtmlWriter writer
+ * @since 3.1.1
+ */
+ protected function renderPrompt($writer)
+ {
+ $text=$this->getPromptText();
+ $value=$this->getPromptValue();
+ if($text==='')
+ $text=$value;
+ if($value==='')
+ $value=$text;
+ if($text!=='')
+ {
+ $writer->addAttribute('value',$value);
+ $writer->renderBeginTag('option');
+ $writer->write(THttpUtility::htmlEncode($text));
+ $writer->renderEndTag();
+ $writer->writeLine();
+ }
+ }
+
+ /**
* Renders body content of the list control.
* This method renders items contained in the list control as the body content.
* @param THtmlWriter writer
@@ -736,6 +797,8 @@ abstract class TListControl extends TDataBoundControl implements IDataRenderer
if($this->_items)
{
$writer->writeLine();
+ if($this->_items->getCount())
+ $this->renderPrompt($writer);
$previousGroup=null;
foreach($this->_items as $item)
{