summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes5
-rw-r--r--HISTORY1
-rw-r--r--demos/quickstart/protected/controls/DocLink.php3
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page41
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php23
-rw-r--r--demos/quickstart/protected/pages/Controls/Validation.page35
-rw-r--r--framework/I18N/core/Gettext/MO.php1
-rw-r--r--framework/I18N/core/Gettext/PO.php1
-rw-r--r--framework/I18N/core/MessageSource_XLIFF.php1
-rw-r--r--framework/Web/Javascripts/js/validator.js3
-rw-r--r--framework/Web/Javascripts/prado/validation3.js2
-rw-r--r--tests/FunctionalTests/tickets/protected/pages/Ticket278.page42
-rw-r--r--tests/FunctionalTests/tickets/protected/pages/Ticket278.php23
-rw-r--r--tests/FunctionalTests/tickets/tests/Ticket278TestCase.php54
14 files changed, 233 insertions, 2 deletions
diff --git a/.gitattributes b/.gitattributes
index 59691acb..59fc1a0d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -854,6 +854,8 @@ demos/quickstart/protected/pages/Controls/Samples/TCheckBox/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TCheckBox/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php -text
+demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page -text
+demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.page -text
demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php -text
demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.page -text
@@ -1631,6 +1633,8 @@ tests/FunctionalTests/tickets/protected/pages/Ticket239.php -text
tests/FunctionalTests/tickets/protected/pages/Ticket269.page -text
tests/FunctionalTests/tickets/protected/pages/Ticket27.page -text
tests/FunctionalTests/tickets/protected/pages/Ticket274.page -text
+tests/FunctionalTests/tickets/protected/pages/Ticket278.page -text
+tests/FunctionalTests/tickets/protected/pages/Ticket278.php -text
tests/FunctionalTests/tickets/protected/pages/Ticket28.page -text
tests/FunctionalTests/tickets/protected/pages/Ticket28.php -text
tests/FunctionalTests/tickets/protected/pages/Ticket284.page -text
@@ -1658,6 +1662,7 @@ tests/FunctionalTests/tickets/tests/Ticket191TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket21TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket239TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket274TestCase.php -text
+tests/FunctionalTests/tickets/tests/Ticket278TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket27TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket284TestCase.php -text
tests/FunctionalTests/tickets/tests/Ticket285TestCase.php -text
diff --git a/HISTORY b/HISTORY
index bb2026ca..8d3aa63f 100644
--- a/HISTORY
+++ b/HISTORY
@@ -20,6 +20,7 @@ ENH: Ticket#223 - Use TRequiredFieldValidator for TRadioButtons with GroupName p
ENH: StringLength, multi-byte, check in TRangeValidator (Wei)
ENH: Ticket#263 - TListBox and TDropDownList support optgroup now (Qiang)
ENH: Ticket#277 - Added TControl.CustomData property (Qiang)
+ENH: Ticket#278 - client-side validator enable/disable (conditional) (Wei)
ENH: Ticket#287 - TControl::broadcastEvent() may raise events now (Qiang)
ENH: Ticket#292 - Added THttpRequest::parseUrl() so that it is easier to be extended (Qiang)
ENH: Ticket#309 - Added THttpRequest.UrlParamSeparator property (Qiang)
diff --git a/demos/quickstart/protected/controls/DocLink.php b/demos/quickstart/protected/controls/DocLink.php
index 74398efb..e8ca7dfa 100644
--- a/demos/quickstart/protected/controls/DocLink.php
+++ b/demos/quickstart/protected/controls/DocLink.php
@@ -22,7 +22,8 @@ class DocLink extends THyperLink
{
$classFile=array_pop($paths).'.html';
$this->setNavigateUrl(self::BASE_URL . '/' . implode('.',$paths) . '/' . $classFile);
- $this->setText('API Manual');
+ if($this->getText() === '')
+ $this->setText('API Manual');
}
}
}
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page
new file mode 100644
index 00000000..e96e7c12
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.page
@@ -0,0 +1,41 @@
+<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>
+
+ <com:TPanel ID="panel1" Style="display:none" >
+ <com:TLabel ForControl="text2" Text="Text 2:" />
+ <com:TTextBox ID="text2" />
+
+ <com:TRequiredFieldValidator
+ ID="validator2"
+ ControlToValidate="text2"
+ OnValidate="validator2_onValidate"
+ OnPreRender="validate2_onPostValidate"
+ ErrorMessage="Text 2 is required">
+ <prop:ClientSide.OnValidate>
+ validator.enabled = $("<%= $this->check1->ClientID %>").checked;
+ </prop:ClientSide.OnValidate>
+ </com:TRequiredFieldValidator>
+
+ </com:TPanel>
+
+ <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>
+</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
new file mode 100644
index 00000000..c5440996
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php
@@ -0,0 +1,23 @@
+<?php
+
+class Home extends TPage
+{
+ function validator2_onValidate($sender, $param)
+ {
+ $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";
+ }
+}
+
+?> \ 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 12836b8c..2241f346 100644
--- a/demos/quickstart/protected/pages/Controls/Validation.page
+++ b/demos/quickstart/protected/pages/Controls/Validation.page
@@ -151,4 +151,39 @@ The summary can be displayed as a list, a bulleted list, or a single paragraph b
</p>
<com:RunBar PagePath="Controls.Samples.TValidationSummary.Home" />
+<h2>Client and Server Side Conditional Validation</h2>
+<p>
+ All validators contains the following events.
+ <ul>
+ <li>The <tt>OnValidate</tt> event is raise before the validator validation functions are called.</li>
+ <li>The <tt>OnSuccess</tt> event is raised after the validator has successfully validate the control.</li>
+ <li>The <tt>OnError</tt> event is raised after the validator fails validation.</li>
+ </ul>
+ The corresponding events for the client side is available as sub-properties
+ of the <tt>ClientSide</tt> property of the validator.
+</p>
+<p>The following example pop-up a message saying "hello" when the validator fails on the client-side.
+<com:TTextHighlighter Language="prado" CssClass="source">
+&lt;com:TRequiredFieldValidator ... &gt;
+ &lt;prop:ClientSide.OnError&gt;
+ alert("hello");
+ &lt;/prop:ClientSide.OnError&gt;
+&lt;/com:TRequiredFieldValidator&gt;
+</com:TTextHighlighter>
+The resulting client-side event callback function is of the following form.
+<com:TTextHighlighter Language="javascript" CssClass="source">
+function onErrorHandler(validator, sender)
+{
+ alert("hello");
+}
+</com:TTextHighlighter>
+Where <tt>validator</tt> is the current client-side validator and <tt>sender</tt>
+is the control that invoked the validator.
+</p>
+<h3>Conditional Validation Example</h3>
+<p>
+The following example show the use of client-side and server side validator events. The example
+demonstrates conditional validation.
+<com:RunBar PagePath="Controls.Samples.TClientSideValidator.Home" />
+</p>
</com:TContent> \ No newline at end of file
diff --git a/framework/I18N/core/Gettext/MO.php b/framework/I18N/core/Gettext/MO.php
index f3be1a30..a93e956f 100644
--- a/framework/I18N/core/Gettext/MO.php
+++ b/framework/I18N/core/Gettext/MO.php
@@ -349,6 +349,7 @@ class TGettext_MO extends TGettext
// done
@flock($this->_handle, LOCK_UN);
@fclose($this->_handle);
+ chmod($file,0777);
return true;
}
}
diff --git a/framework/I18N/core/Gettext/PO.php b/framework/I18N/core/Gettext/PO.php
index 3c69c091..90942fa1 100644
--- a/framework/I18N/core/Gettext/PO.php
+++ b/framework/I18N/core/Gettext/PO.php
@@ -154,6 +154,7 @@ class TGettext_PO extends TGettext
//done
@flock($fh, LOCK_UN);
@fclose($fh);
+ chmod($file,0777);
return true;
}
}
diff --git a/framework/I18N/core/MessageSource_XLIFF.php b/framework/I18N/core/MessageSource_XLIFF.php
index 15af971a..7f2f27c5 100644
--- a/framework/I18N/core/MessageSource_XLIFF.php
+++ b/framework/I18N/core/MessageSource_XLIFF.php
@@ -481,6 +481,7 @@ class MessageSource_XLIFF extends MessageSource
if(!is_dir($dir))
throw new TException("Unable to create directory $dir");
file_put_contents($file, $this->getTemplate($catalogue));
+ chmod($file, 0777);
return array($variant, $file);
}
diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js
index 0e39d191..cecc6881 100644
--- a/framework/Web/Javascripts/js/validator.js
+++ b/framework/Web/Javascripts/js/validator.js
@@ -96,7 +96,8 @@ control.addClassName(CssClass);}},hide:function()
{this.isValid=true;this.updateControl();this.visible=false;},validate:function(invoker)
{if(typeof(this.options.OnValidate)=="function")
this.options.OnValidate(this,invoker);if(this.enabled)
-this.isValid=this.evaluateIsValid();if(this.isValid)
+this.isValid=this.evaluateIsValid();else
+this.isValid=true;if(this.isValid)
{if(typeof(this.options.OnSuccess)=="function")
{this.visible=true;this.message.style.visibility="visible";this.updateControlCssClass(this.control,this.isValid);this.options.OnSuccess(this,invoker);}
else
diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js
index b1b20722..139f99f1 100644
--- a/framework/Web/Javascripts/prado/validation3.js
+++ b/framework/Web/Javascripts/prado/validation3.js
@@ -652,6 +652,8 @@ Prado.WebUI.TBaseValidator.prototype =
if(this.enabled)
this.isValid = this.evaluateIsValid();
+ else
+ this.isValid = true;
if(this.isValid)
{
diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket278.page b/tests/FunctionalTests/tickets/protected/pages/Ticket278.page
new file mode 100644
index 00000000..75aed4d9
--- /dev/null
+++ b/tests/FunctionalTests/tickets/protected/pages/Ticket278.page
@@ -0,0 +1,42 @@
+<com:TContent ID="Content">
+
+ <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>
+
+ <com:TPanel ID="panel1" Style="display:none" >
+ <com:TLabel ForControl="text2" Text="Text 2:" />
+ <com:TTextBox ID="text2" />
+
+ <com:TRequiredFieldValidator
+ ID="validator2"
+ ControlToValidate="text2"
+ OnValidate="validator2_onValidate"
+ OnPreRender="validate2_onPostValidate"
+ ErrorMessage="Text 2 is required">
+ <prop:ClientSide.OnValidate>
+ validator.enabled = $("<%= $this->check1->ClientID %>").checked;
+ </prop:ClientSide.OnValidate>
+ </com:TRequiredFieldValidator>
+
+ </com:TPanel>
+
+ <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>
+
+</com:TContent> \ No newline at end of file
diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket278.php b/tests/FunctionalTests/tickets/protected/pages/Ticket278.php
new file mode 100644
index 00000000..1aadee77
--- /dev/null
+++ b/tests/FunctionalTests/tickets/protected/pages/Ticket278.php
@@ -0,0 +1,23 @@
+<?php
+
+class Ticket278 extends TPage
+{
+ function validator2_onValidate($sender, $param)
+ {
+ $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";
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/FunctionalTests/tickets/tests/Ticket278TestCase.php b/tests/FunctionalTests/tickets/tests/Ticket278TestCase.php
new file mode 100644
index 00000000..bd631c14
--- /dev/null
+++ b/tests/FunctionalTests/tickets/tests/Ticket278TestCase.php
@@ -0,0 +1,54 @@
+<?php
+
+class Ticket278TestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $base = 'ctl0_Content_';
+ $this->open('tickets/index.php?page=Ticket278');
+ $this->assertTitle('Verifying Ticket 278');
+ $this->assertNotVisible($base.'validator1');
+ $this->assertNotVisible($base.'validator2');
+ $this->assertNotVisible($base.'panel1');
+
+ $this->click($base.'button1');
+ $this->assertVisible($base.'validator1');
+ $this->assertNotVisible($base.'validator2');
+
+ $this->type($base.'text1', 'asd');
+ $this->clickAndWait($base.'button1');
+ $this->assertNotVisible($base.'validator1');
+ $this->assertNotVisible($base.'validator2');
+ $this->assertNotVisible($base.'panel1');
+
+ $this->click($base.'check1');
+ $this->click($base.'button1');
+ $this->assertNotVisible($base.'validator1');
+ $this->assertVisible($base.'validator2');
+ $this->assertVisible($base.'panel1');
+
+
+ $this->type($base.'text1', '');
+ $this->type($base.'text2', 'asd');
+ $this->click($base.'button1');
+ $this->assertVisible($base.'validator1');
+ $this->assertNotVisible($base.'validator2');
+ $this->assertVisible($base.'panel1');
+
+
+ $this->type($base.'text1', 'asd');
+ $this->clickAndWait($base.'button1');
+ $this->assertNotVisible($base.'validator1');
+ $this->assertNotVisible($base.'validator2');
+ $this->assertVisible($base.'panel1');
+
+ $this->type($base.'text1', '');
+ $this->type($base.'text2', '');
+ $this->click($base.'button1');
+ $this->assertVisible($base.'validator1');
+ $this->assertVisible($base.'validator2');
+ $this->assertVisible($base.'panel1');
+ }
+}
+
+?> \ No newline at end of file