From f884ea21ea8f0c6ced02565bd647a5692f82aea4 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 25 Jan 2006 04:26:27 +0000 Subject: Added validation demo for TListBox. Fixed a few autopostback with causesvalidation problems. --- .../pages/Controls/Samples/TListBox/Home.page | 55 +++++++++++++++++++++- framework/Web/UI/WebControls/TCheckBoxList.php | 9 +--- framework/Web/UI/WebControls/TDropDownList.php | 9 +--- framework/Web/UI/WebControls/TListBox.php | 21 +++++---- 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page index 161f68a4..9f9bf162 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.page @@ -94,7 +94,7 @@ List box's behavior upon postback:

List Boxes in Multiple Selection Mode

-Use Shift + Mouse Click to change selection +Use Ctrl + Mouse Click to change selection
@@ -159,7 +159,7 @@ Auto postback list box:

List Boxes with DataBinding

-Use Shift + Mouse Click to change selection +Use Ctrl + Mouse Click to change selection
@@ -206,4 +206,55 @@ Databind with DataTextField and DataValueField specified:
+ + +

List Boxes with Validation

+ + + + + + + + + + + + + +
+List box is being validated: + + + + + + + + + +
+List box causing validation: + + + + + + + +
+ \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php index 168c7ef0..34ff005f 100644 --- a/framework/Web/UI/WebControls/TCheckBoxList.php +++ b/framework/Web/UI/WebControls/TCheckBoxList.php @@ -328,13 +328,8 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont */ public function raisePostDataChangedEvent() { - $page=$this->getPage(); - if($this->getAutoPostBack() && !$page->getPostBackEventTarget()) - { - $page->setPostBackEventTarget($this); - if($this->getCausesValidation()) - $page->validate($this->getValidationGroup()); - } + if($this->getAutoPostBack() && $this->getCausesValidation()) + $this->getPage()->validate($this->getValidationGroup()); $this->onSelectedIndexChanged(null); } diff --git a/framework/Web/UI/WebControls/TDropDownList.php b/framework/Web/UI/WebControls/TDropDownList.php index 3c459057..a3c02c15 100644 --- a/framework/Web/UI/WebControls/TDropDownList.php +++ b/framework/Web/UI/WebControls/TDropDownList.php @@ -72,13 +72,8 @@ class TDropDownList extends TListControl implements IPostBackDataHandler */ public function raisePostDataChangedEvent() { - $page=$this->getPage(); - if($this->getAutoPostBack() && !$page->getPostBackEventTarget()) - { - $page->setPostBackEventTarget($this); - if($this->getCausesValidation()) - $page->validate($this->getValidationGroup()); - } + if($this->getAutoPostBack() && $this->getCausesValidation()) + $this->getPage()->validate($this->getValidationGroup()); $this->onSelectedIndexChanged(null); } diff --git a/framework/Web/UI/WebControls/TListBox.php b/framework/Web/UI/WebControls/TListBox.php index 47165c99..50cf3873 100644 --- a/framework/Web/UI/WebControls/TListBox.php +++ b/framework/Web/UI/WebControls/TListBox.php @@ -29,7 +29,7 @@ Prado::using('System.Web.UI.WebControls.TListControl'); * @package System.Web.UI.WebControls * @since 3.0 */ -class TListBox extends TListControl implements IPostBackDataHandler +class TListBox extends TListControl implements IPostBackDataHandler, IValidatable { /** * Adds attribute name-value pairs to renderer. @@ -131,13 +131,8 @@ class TListBox extends TListControl implements IPostBackDataHandler */ public function raisePostDataChangedEvent() { - $page=$this->getPage(); - if($this->getAutoPostBack() && !$page->getPostBackEventTarget()) - { - $page->setPostBackEventTarget($this); - if($this->getCausesValidation()) - $page->validate($this->getValidationGroup()); - } + if($this->getAutoPostBack() && $this->getCausesValidation()) + $this->getPage()->validate($this->getValidationGroup()); $this->onSelectedIndexChanged(null); } @@ -184,5 +179,15 @@ class TListBox extends TListControl implements IPostBackDataHandler { $this->setViewState('SelectionMode',TPropertyValue::ensureEnum($value,array('Single','Multiple')),'Single'); } + + /** + * Returns the value to be validated. + * This methid is required by IValidatable interface. + * @return mixed the value of the property to be validated. + */ + public function getValidationPropertyValue() + { + return $this->getSelectedValue(); + } } ?> \ No newline at end of file -- cgit v1.2.3