From 95cc364ff7afdf2b70c1332e6980141a9645b304 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 28 Sep 2007 01:50:32 +0000 Subject: Added support to prompt list item. --- framework/Web/UI/WebControls/TDropDownList.php | 4 ++ framework/Web/UI/WebControls/TListControl.php | 63 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) (limited to 'framework/Web/UI') 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 in template * * + * 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 * @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 @@ -703,6 +703,44 @@ abstract class TListControl extends TDataBoundControl implements IDataRenderer $this->setViewState('ValidationGroup',$value,''); } + /** + * @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 @@ -726,6 +764,29 @@ abstract class TListControl extends TDataBoundControl implements IDataRenderer $this->raiseEvent('OnTextChanged',$this,$param); } + /** + * 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. @@ -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) { -- cgit v1.2.3