diff options
11 files changed, 203 insertions, 57 deletions
diff --git a/.gitattributes b/.gitattributes index be7efd73..ec41c3e0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1043,6 +1043,8 @@ demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/LabeledTextBox demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/Home.page -text demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/Home.php -text demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php -text +demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.page -text +demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.php -text demos/quickstart/protected/pages/Controls/Samples/TBulletedList/Home.page -text demos/quickstart/protected/pages/Controls/Samples/TBulletedList/Home.php -text demos/quickstart/protected/pages/Controls/Samples/TBulletedList/bullet.gif -text @@ -2428,6 +2430,8 @@ tests/FunctionalTests/validators/protected/pages/CausesValidation.page -text tests/FunctionalTests/validators/protected/pages/CheckBox.page -text tests/FunctionalTests/validators/protected/pages/CheckBox.php -text tests/FunctionalTests/validators/protected/pages/CompareValidator.page -text +tests/FunctionalTests/validators/protected/pages/ConditionalValidation.page -text +tests/FunctionalTests/validators/protected/pages/ConditionalValidation.php -text tests/FunctionalTests/validators/protected/pages/CustomValidator.page -text tests/FunctionalTests/validators/protected/pages/CustomValidator.php -text tests/FunctionalTests/validators/protected/pages/DataTypeValidator.page -text @@ -2452,6 +2456,7 @@ tests/FunctionalTests/validators/protected/pages/config.xml -text tests/FunctionalTests/validators/tests/ButtonTestCase.php -text tests/FunctionalTests/validators/tests/CheckBoxTestCase.php -text tests/FunctionalTests/validators/tests/CompareValidatorTestCase.php -text +tests/FunctionalTests/validators/tests/ConditionalValidationTestCase.php -text tests/FunctionalTests/validators/tests/CustomValidatorTestCase.php -text tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php -text tests/FunctionalTests/validators/tests/DatePickerTestCase.php -text diff --git a/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.page b/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.page new file mode 100644 index 00000000..44f84abe --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.page @@ -0,0 +1,25 @@ +<com:TContent ID="body">
+
+<h1>Reset Validation using Javascript</h1>
+
+<table class="sampletable">
+
+<tr>
+<td class="samplenote">
+Validator with default settings:
+</td>
+<td class="sampleaction">
+<com:TTextBox ID="TextBox1" />
+<com:TRequiredFieldValidator
+ ValidationGroup="Group1"
+ ControlToValidate="TextBox1"
+ Text="Field required." />
+<com:TButton Text="Submit" ValidationGroup="Group1" />
+
+<a href="javascript: Prado.Validation.reset('Group1')">Reset Validation</a>
+</td>
+</tr>
+
+</table>
+
+<div class="last-modified">$Id: Home.page 1650 2007-01-24 06:55:32Z wei $</div></com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.php b/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.php new file mode 100644 index 00000000..88d2dbf2 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.php @@ -0,0 +1,8 @@ +<?php
+
+class Home extends TPage
+{
+
+}
+
+?>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page index c70e04c7..76ecb845 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page @@ -1,41 +1,36 @@ <com:TContent ID="body">
- <h1>Validator Toggle - Server and Client Side</h1>
- <com:TLabel ForControl="text1" Text="Text 1:" />
- <com:TTextBox ID="text1" />
- <com:TRequiredFieldValidator
- ID="validator1"
- ControlToValidate="text1"
- ErrorMessage="Text 1 is required" />
- <div>
- <com:TCheckBox ID="check1" Text="More..." />
- </div>
+<h1>Conditional Validation (client-side + server side)</h1>
- <com:TPanel ID="panel1" Style="display:none" >
- <com:TLabel ForControl="text2" Text="Text 2:" />
+<table class="sampletable">
+<tr>
+<td class="samplenote">
+Validator with default settings:<br />
+Check "optional" to validate both textboxes
+</td>
+<td class="sampleaction">
+ <com:TTextBox ID="text1" />
+ <com:TRequiredFieldValidator
+ ID="validator1"
+ ControlToValidate="text1"
+ ErrorMessage="*"
+ ControlCssClass="required"/>
<com:TTextBox ID="text2" />
+ <com:TRequiredFieldValidator
+ ID="validator2"
+ ControlToValidate="text2"
+ OnValidate="check_validate"
+ ErrorMessage="*"
+ ControlCssClass="required">
+ <prop:ClientSide.OnValidate>
+ sender.enabled = $('<%= $this->check1->ClientID %>').checked;
+ </prop:ClientSide.OnValidate>
- <com:TRequiredFieldValidator
- ID="validator2"
- ControlToValidate="text2"
- OnValidate="validator2_onValidate"
- OnPreRender="validate2_onPostValidate"
- ErrorMessage="Text 2 is required">
- <prop:ClientSide.OnValidate>
- sender.enabled = $("<%= $this->check1->ClientID %>").checked;
- </prop:ClientSide.OnValidate>
- </com:TRequiredFieldValidator>
+ </com:TRequiredFieldValidator>
+ <com:TCheckBox ID="check1" Text="Optional" />
+ <com:TButton ID="submit1" Text="Submit" />
+</td>
+</tr>
- </com:TPanel>
+</table>
- <com:TButton ID="button1" Text="Submit!" />
-
- <com:TClientScript>
- Event.OnLoad(function()
- {
- Event.observe("<%= $this->check1->ClientID %>", "click", function(ev)
- {
- $("<%= $this->panel1->ClientID %>").toggle();
- });
- });
- </com:TClientScript>
<div class="last-modified">$Id$</div></com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php index c5440996..d6dded08 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php @@ -2,22 +2,16 @@ class Home extends TPage
{
- function validator2_onValidate($sender, $param)
+ function check_validate($sender, $params)
{
- $sender->Enabled = $this->check1->Checked;
+ $sender->enabled = $this->check1->checked;
}
-
- function validate2_onPostValidate($sender, $param)
- {
- $sender->Enabled = true;
- }
-
+
function onPreRender($param)
{
- parent::onPreRender($param);
- $this->panel1->Style =
- $this->check1->Checked ? "display:block" : "display:none";
- }
+ //always re-enable the validator2 so as to display the client-side validator
+ $this->validator2->enabled=true;
+ }
}
?>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Validation.page b/demos/quickstart/protected/pages/Controls/Validation.page index 38699550..b93f6d49 100644 --- a/demos/quickstart/protected/pages/Controls/Validation.page +++ b/demos/quickstart/protected/pages/Controls/Validation.page @@ -31,14 +31,7 @@ Validators share a common set of properties, which are defined in the base class <li><tt>FocusElementID</tt> - the ID of the HTML element that will receive focus if validation fails and <tt>FocusOnError</tt> is true.</li>
</ul>
-<h1 id="123123">Interacting the Validators with Javascript</h1>
-<h2>Resetting or Clearing of Validators</h2>
-<p id="1212323">
-Validators can be reset on the client-side using javascript by calling the
-<tt>Prado.Validation.reset(groupID)</tt> where <tt>groupID</tt> is the validator
-grouping name. If <tt>groupID</tt> is null, then validators without grouping are used.
-</p>
-
+<h1>Prado Validation Controls</h1>
<a name="TRequiredFieldValidator"></a>
<h2 id="4902">TRequiredFieldValidator</h2>
<p id="560340" class="block-content">
@@ -159,6 +152,24 @@ The summary can be displayed as a list, a bulleted list, or a single paragraph b </p>
<com:RunBar PagePath="Controls.Samples.TValidationSummary.Home" />
+<h1 id="123123">Interacting the Validators</h1>
+<h2>Resetting or Clearing of Validators</h2>
+<p id="1212323">
+Validators can be reset on the client-side using javascript by calling the
+<tt>Prado.Validation.reset(groupID)</tt> where <tt>groupID</tt> is the validator
+grouping name. If <tt>groupID</tt> is null, then validators without grouping are used.
+</p>
+
+<com:TTextHighlighter Language="javascript" CssClass="source block-content" id="code_560118a">
+<script type="text/javascript">
+function reset_validator()
+{
+ Prado.Validation.reset("group1");
+}
+</script>
+</com:TTextHighlighter>
+<com:RunBar PagePath="Controls.Samples.ResetValidation.Home" />
+
<h2 id="5301">Client and Server Side Conditional Validation</h2>
<p id="560359" class="block-content">
All validators contains the following events.
@@ -191,7 +202,9 @@ is the control that invoked the validator. <h3 id="5302">Conditional Validation Example</h3>
<p id="560361" class="block-content">
The following example show the use of client-side and server side validator events. The example
-demonstrates conditional validation.
+demonstrates conditional validation. Notice that, we need to write code for both the
+server side and client-side. Moreover, on the server side, we need to re-enable the conditional
+validator so that its javascript code are produced no matter what (otherwise, the client-side validator is not available).
<com:RunBar PagePath="Controls.Samples.TClientSideValidator.Home" />
</p>
diff --git a/demos/quickstart/protected/pages/GettingStarted/Introduction.page b/demos/quickstart/protected/pages/GettingStarted/Introduction.page index e48360d6..f267d23d 100644 --- a/demos/quickstart/protected/pages/GettingStarted/Introduction.page +++ b/demos/quickstart/protected/pages/GettingStarted/Introduction.page @@ -7,6 +7,7 @@ This Quickstart tutorial is provided to help you quickly start building your own <p>
If you are an existing PRADO 3.x user and would like to learn what enhancements are available for each new version, please check out the <a href="?page=GettingStarted.NewFeatures">new features</a> page. Otherwise, the following sections are helpful for newbies.
</p>
+<!--
<div class="start-page">
<div class="concepts start-block">
<h2>How PRADO Works</h2>
@@ -44,7 +45,7 @@ If you are an existing PRADO 3.x user and would like to learn what enhancements </ul>
</div>
</div>
-
+-->
<p id="10002">
You may refer to the following resources if you find this tutorial does not fulfill all your needs.
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index ac2d53b8..99a81375 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -483,9 +483,9 @@ abstract class TBaseValidator extends TLabel implements IValidator public function validate() { $this->setIsValid(true); + $this->onValidate(); if($this->getVisible(true) && $this->getEnabled(true)) { - $this->onValidate(); if($this->getValidationTarget()) { if($this->evaluateIsValid()) diff --git a/tests/FunctionalTests/validators/protected/pages/ConditionalValidation.page b/tests/FunctionalTests/validators/protected/pages/ConditionalValidation.page new file mode 100644 index 00000000..ad43135b --- /dev/null +++ b/tests/FunctionalTests/validators/protected/pages/ConditionalValidation.page @@ -0,0 +1,30 @@ +<com:TContent ID="Content">
+<h1>Conditional Validation (clientside + server side)</h1>
+<div>
+ <div>
+ <com:TTextBox ID="text1" />
+ <com:TRequiredFieldValidator
+ ID="validator1"
+ ControlToValidate="text1"
+ ErrorMessage="*"
+ ControlCssClass="required"/>
+ <com:TTextBox ID="text2" />
+ <com:TRequiredFieldValidator
+ ID="validator2"
+ ControlToValidate="text2"
+ OnValidate="check_validate"
+ ErrorMessage="*"
+ ControlCssClass="required">
+ <prop:ClientSide.OnValidate>
+ sender.enabled = $('<%= $this->check1->ClientID %>').checked;
+ </prop:ClientSide.OnValidate>
+
+ </com:TRequiredFieldValidator>
+ <com:TCheckBox ID="check1" />
+ </div>
+ <com:TButton ID="submit1" Text="Submit" />
+</div>
+
+
+
+</com:TContent>
\ No newline at end of file diff --git a/tests/FunctionalTests/validators/protected/pages/ConditionalValidation.php b/tests/FunctionalTests/validators/protected/pages/ConditionalValidation.php new file mode 100644 index 00000000..7756566c --- /dev/null +++ b/tests/FunctionalTests/validators/protected/pages/ConditionalValidation.php @@ -0,0 +1,20 @@ +<?php
+/*
+ * Created on 27/03/2007
+ */
+
+class ConditionalValidation extends TPage
+{
+ function check_validate($sender, $params)
+ {
+ $sender->enabled = $this->check1->checked;
+ }
+
+ function onPreRender($param)
+ {
+ //always re-enable the validator2 so as to display the client-side validator
+ $this->validator2->enabled=true;
+ }
+}
+
+?>
diff --git a/tests/FunctionalTests/validators/tests/ConditionalValidationTestCase.php b/tests/FunctionalTests/validators/tests/ConditionalValidationTestCase.php new file mode 100644 index 00000000..7191ff9f --- /dev/null +++ b/tests/FunctionalTests/validators/tests/ConditionalValidationTestCase.php @@ -0,0 +1,55 @@ +<?php
+
+class ConditionalValidationTestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $base = "ctl0_Content_";
+ $this->open("validators/index.php?page=ConditionalValidation", "");
+ $this->verifyTextPresent("Conditional Validation (clientside + server side)", "");
+ $this->assertNotVisible("{$base}validator1", "");
+ $this->assertNotVisible("{$base}validator2", "");
+
+ $this->click("{$base}submit1");
+ $this->assertVisible("{$base}validator1", "");
+ $this->assertNotVisible("{$base}validator2", "");
+
+ $this->click("{$base}check1");
+ $this->click("{$base}submit1");
+ $this->assertVisible("{$base}validator1", "");
+ $this->assertVisible("{$base}validator2", "");
+
+ $this->click("{$base}check1");
+ $this->click("{$base}submit1");
+ $this->assertVisible("{$base}validator1", "");
+ $this->assertNotVisible("{$base}validator2", "");
+
+ $this->type("{$base}text1", "testing");
+ $this->clickAndWait("{$base}submit1");
+ $this->assertNotVisible("{$base}validator1", "");
+ $this->assertNotVisible("{$base}validator2", "");
+
+ $this->type("{$base}text1" ,"");
+ $this->click("{$base}check1");
+ $this->click("{$base}submit1");
+ $this->assertVisible("{$base}validator1", "");
+ $this->assertVisible("{$base}validator2", "");
+
+ $this->type("{$base}text1", "test");
+ $this->type("{$base}text2", "123");
+ $this->clickAndWait("{$base}submit1");
+ $this->assertNotVisible("{$base}validator1", "");
+ $this->assertNotVisible("{$base}validator2", "");
+
+ $this->click("{$base}check1");
+ $this->type("{$base}text1", "");
+ $this->type("{$base}text2", "");
+ $this->click("{$base}submit1");
+ $this->assertVisible("{$base}validator1", "");
+ $this->assertNotVisible("{$base}validator2", "");
+
+ }
+
+}
+
+?>
|