From 57832028ea4380f2c185c18d857d2c6b7682e763 Mon Sep 17 00:00:00 2001
From: "ctrlaltca@gmail.com" <>
Date: Wed, 21 Dec 2011 15:19:37 +0000
Subject: fix for #91; fixed TActiveCustomvalidator's behaviour and demo (more
discussion in the ticket)
---
HISTORY | 1 +
.../Samples/TActiveCustomValidator/Home.page | 2 +-
.../source/prado/validator/validation3.js | 78 +++++-----------------
.../UI/ActiveControls/TActiveCustomValidator.php | 14 ++++
4 files changed, 33 insertions(+), 62 deletions(-)
diff --git a/HISTORY b/HISTORY
index 0ff1d8ea..56d50195 100644
--- a/HISTORY
+++ b/HISTORY
@@ -22,6 +22,7 @@ BUG: TCaptcha: publish images with image/png content-type (ctrlaltca)
BUG: Issue #35 - [840] Capital letters for the initial letter of the directories name (ctrlaltca)
BUG: Issue #66 - TButton.CausesValidation=False ignored when pressing Enter on the button within a control with DefaultButton (ctrlaltca)
NEW: Issue #83 - PHP configuration style (Carl)
+BUG: Issue #91 - TActiveCustomValidator can not be updated in JavaScript callback (ctrlaltca)
ENH: Issue #106 - TJavaScript::jsonEncode and TJavaScript::jsonDecode should use built-in PHP functions (ctrlaltca)
ENH: Issue #173 - Add "dragdropextra" (supergsting) patch, mouse coordinates and key status to drag & drop controls (Christophe, DevWorx)
BUG: Issue #179 - Serialization issues in Prado (ctrlaltca)
diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCustomValidator/Home.page b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCustomValidator/Home.page
index e71e60c8..8ef69a9a 100644
--- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCustomValidator/Home.page
+++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCustomValidator/Home.page
@@ -12,7 +12,7 @@ Custom validator using callbacks:
ControlToValidate="textbox1"
ErrorMessage="Please enter 'Prado'"
OnServerValidate="validator1_onvalidate" />
-
+
diff --git a/framework/Web/Javascripts/source/prado/validator/validation3.js b/framework/Web/Javascripts/source/prado/validator/validation3.js
index bbf3929a..f9f42232 100644
--- a/framework/Web/Javascripts/source/prado/validator/validation3.js
+++ b/framework/Web/Javascripts/source/prado/validator/validation3.js
@@ -212,6 +212,20 @@ Object.extend(Prado.Validation,
}
});
});
+ },
+
+ updateActiveCustomValidator : function(validatorID, isValid)
+ {
+ $H(Prado.Validation.managers).each(function(manager)
+ {
+ manager[1].validators.each(function(validator)
+ {
+ if(validator.options.ID == validatorID)
+ {
+ validator.updateIsValid(isValid);
+ }
+ });
+ });
}
});
@@ -1505,17 +1519,6 @@ Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
*/
Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
- /**
- * Value to validate
- * @var {string} validatingValue
- */
- validatingValue : null,
- /**
- * DOM element that triggered validation
- * @var {element} invoker
- */
- invoker : null,
-
/**
* Override the parent implementation to store the invoker, in order to
* re-validate after the callback has returned
@@ -1545,18 +1548,7 @@ Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
this.options.OnValidate(this, invoker);
}
- if(this.enabled && !this.control.getAttribute('disabled'))
- this.isValid = this.evaluateIsValid();
- else
- this.isValid = true;
-
- // Only update the message if the callback has already return !
- if (!this.requestDispatched)
- this.updateValidationDisplay(invoker);
-
- this.observeChanges(this.control);
-
- return this.isValid;
+ return true;
},
/**
@@ -1566,21 +1558,6 @@ Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
*/
evaluateIsValid : function()
{
- var value = this.getValidationValue();
- if(!this.requestDispatched && (""+value) != (""+this.validatingValue))
- {
- this.validatingValue = value;
- var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
- if(this.options.DateFormat && value instanceof Date) //change date to string with formatting.
- value = value.SimpleFormat(this.options.DateFormat);
- request.setCallbackParameter(value);
- request.setCausesValidation(false);
- request.options.onSuccess = this.callbackOnSuccess.bind(this);
- request.options.onFailure = this.callbackOnFailure.bind(this);
- request.dispatch();
- this.requestDispatched = true;
- return false;
- }
return this.isValid;
},
@@ -1590,36 +1567,15 @@ Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
* @param {CallbackRequest} request - CallbackRequest.
* @param {string} data - Response data.
*/
- callbackOnSuccess : function(request, data)
+ updateIsValid : function(data)
{
this.isValid = data;
this.requestDispatched = false;
if(typeof(this.options.onSuccess) == "function")
- this.options.onSuccess(request,data);
+ this.options.onSuccess(null,data);
this.updateValidationDisplay();
this.manager.updateSummary(this.group);
- // Redispatch initial request if any
- if(this.isValid) {
- if(this.invoker instanceof Prado.CallbackRequest) {
- this.invoker.dispatch();
- } else {
- this.invoker.click();
- }
- }
},
-
- /**
- * Handle callback failure.
- * @function ?
- * @param {CallbackRequest} request - CallbackRequest.
- * @param {string} data - Response data.
- */
- callbackOnFailure : function(request, data)
- {
- this.requestDispatched = false;
- if(typeof(this.options.onFailure) == "function")
- this.options.onFailure(request,data);
- }
});
/**
diff --git a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php
index 80d2f522..e0884c55 100644
--- a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php
+++ b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php
@@ -101,6 +101,20 @@ class TActiveCustomValidator extends TCustomValidator
$this->onCallback($param);
}
+ /**
+ * @param boolean whether the value is valid; this method will trigger a clientside update if needed
+ */
+ public function setIsValid($value)
+ {
+ parent::setIsValid($value);
+ if($this->getActiveControl()->canUpdateClientSide())
+ {
+ $client = $this->getPage()->getCallbackClient();
+ $func = 'Prado.Validation.updateActiveCustomValidator';
+ $client->callClientFunction($func, array($this, $value));
+ }
+ }
+
/**
* This method is invoked when a callback is requested. The method raises
* 'OnCallback' event to fire up the event handlers. If you override this
--
cgit v1.2.3