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) --- .../source/prado/validator/validation3.js | 78 +++++----------------- .../UI/ActiveControls/TActiveCustomValidator.php | 14 ++++ 2 files changed, 31 insertions(+), 61 deletions(-) (limited to 'framework') 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