From 5bd4f1f34bb08469d3e18727f9d39c53037c6424 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sat, 28 Oct 2006 07:43:27 +0000 Subject: Add TActiveCustomValidator to change ErrorMessage on callbback. --- framework/Web/Javascripts/js/compressed/validator.js | 6 +++++- framework/Web/Javascripts/js/debug/validator.js | 15 +++++++++++++++ framework/Web/Javascripts/prado/validation3.js | 15 +++++++++++++++ .../Web/UI/ActiveControls/TActiveCustomValidator.php | 15 +++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/framework/Web/Javascripts/js/compressed/validator.js b/framework/Web/Javascripts/js/compressed/validator.js index 4134ecc3..7b89084b 100644 --- a/framework/Web/Javascripts/js/compressed/validator.js +++ b/framework/Web/Javascripts/js/compressed/validator.js @@ -12,7 +12,11 @@ this.managers[formID].addValidator(validator);else throw new Error("A validation manager for form '"+formID+"' needs to be created first.");return this.managers[formID];},addSummary:function(formID,validator) {if(this.managers[formID]) this.managers[formID].addSummary(validator);else -throw new Error("A validation manager for form '"+formID+"' needs to be created first.");return this.managers[formID];}});Prado.ValidationManager=Class.create();Prado.ValidationManager.prototype={validators:[],summaries:[],groups:[],options:{},initialize:function(options) +throw new Error("A validation manager for form '"+formID+"' needs to be created first.");return this.managers[formID];},setErrorMessage:function(validatorID,message) +{$H(Prado.Validation.managers).each(function(manager) +{manager[1].validators.each(function(validator) +{if(validator.options.ID==validatorID) +{validator.options.ErrorMessage=message;$(validatorID).innerHTML=message;}});});}});Prado.ValidationManager=Class.create();Prado.ValidationManager.prototype={validators:[],summaries:[],groups:[],options:{},initialize:function(options) {this.options=options;Prado.Validation.managers[options.FormID]=this;},validate:function(group,invoker) {if(group) return this._validateGroup(group,invoker);else diff --git a/framework/Web/Javascripts/js/debug/validator.js b/framework/Web/Javascripts/js/debug/validator.js index 8f244667..64ac10e3 100644 --- a/framework/Web/Javascripts/js/debug/validator.js +++ b/framework/Web/Javascripts/js/debug/validator.js @@ -140,6 +140,21 @@ Object.extend(Prado.Validation, else throw new Error("A validation manager for form '"+formID+"' needs to be created first."); return this.managers[formID]; + }, + + setErrorMessage : function(validatorID, message) + { + $H(Prado.Validation.managers).each(function(manager) + { + manager[1].validators.each(function(validator) + { + if(validator.options.ID == validatorID) + { + validator.options.ErrorMessage = message; + $(validatorID).innerHTML = message; + } + }); + }); } }); diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js index 55ebc095..aa4c726b 100644 --- a/framework/Web/Javascripts/prado/validation3.js +++ b/framework/Web/Javascripts/prado/validation3.js @@ -140,6 +140,21 @@ Object.extend(Prado.Validation, else throw new Error("A validation manager for form '"+formID+"' needs to be created first."); return this.managers[formID]; + }, + + setErrorMessage : function(validatorID, message) + { + $H(Prado.Validation.managers).each(function(manager) + { + manager[1].validators.each(function(validator) + { + if(validator.options.ID == validatorID) + { + validator.options.ErrorMessage = message; + $(validatorID).innerHTML = message; + } + }); + }); } }); diff --git a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php index a0ef895c..1668b54f 100644 --- a/framework/Web/UI/ActiveControls/TActiveCustomValidator.php +++ b/framework/Web/UI/ActiveControls/TActiveCustomValidator.php @@ -124,6 +124,21 @@ class TActiveCustomValidator extends TCustomValidator return $options; } + /** + * Sets the text for the error message. Updates client-side erorr message. + * @param string the error message + */ + public function setErrorMessage($value) + { + parent::setErrorMessage($value); + if($this->getActiveControl()->canUpdateClientSide()) + { + $client = $this->getPage()->getCallbackClient(); + $func = 'Prado.Validation.setErrorMessage'; + $client->callClientFunction($func, array($this, $value)); + } + } + /** * Register the javascript for the active custom validator. */ -- cgit v1.2.3