From c5d0cd2824e3c3bb2f6f3834177a71c1d7b78519 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 27 Mar 2007 00:47:38 +0000 Subject: merge from 3.0 branch till 1779. --- framework/Web/Javascripts/js/debug/validator.js | 156 +++++------------------- 1 file changed, 33 insertions(+), 123 deletions(-) (limited to 'framework/Web/Javascripts/js/debug/validator.js') diff --git a/framework/Web/Javascripts/js/debug/validator.js b/framework/Web/Javascripts/js/debug/validator.js index 39ef9d63..170d7ff1 100644 --- a/framework/Web/Javascripts/js/debug/validator.js +++ b/framework/Web/Javascripts/js/debug/validator.js @@ -89,15 +89,6 @@ Object.extend(Prado.Validation, } }, - /** - * @return string first form ID. - */ - getForm : function() - { - var keys = $H(this.managers).keys(); - return keys[0]; - }, - /** * Check if the validators are valid for a particular form (and group). * The validators states will not be changed. @@ -140,21 +131,6 @@ 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; - } - }); - }); } }); @@ -168,6 +144,11 @@ Prado.ValidationManager = Class.create(); */ Prado.ValidationManager.prototype = { + validators : [], // list of validators + summaries : [], // validation summaries + groups : [], // validation groups + options : {}, + /** * * options['FormID']* The ID of HTML form to manage. @@ -175,11 +156,6 @@ Prado.ValidationManager.prototype = */ initialize : function(options) { - this.validators = []; // list of validators - this.summaries = []; // validation summaries - this.groups = []; // validation groups - this.options = {}; - this.options = options; Prado.Validation.managers[options.FormID] = this; }, @@ -357,6 +333,11 @@ Prado.ValidationManager.prototype = Prado.WebUI.TValidationSummary = Class.create(); Prado.WebUI.TValidationSummary.prototype = { + group : null, + options : {}, + visible : false, + messages : null, + /** * * options['ID']* Validation summary ID, i.e., an HTML element ID @@ -376,12 +357,9 @@ Prado.WebUI.TValidationSummary.prototype = this.options = options; this.group = options.ValidationGroup; this.messages = $(options.ID); - if(this.messages) - { - this.visible = this.messages.style.visibility != "hidden" - this.visible = this.visible && this.messages.style.display != "none"; - Prado.Validation.addSummary(options.FormID, this); - } + this.visible = this.messages.style.visibility != "hidden" + this.visible = this.visible && this.messages.style.display != "none"; + Prado.Validation.addSummary(options.FormID, this); }, /** @@ -562,6 +540,15 @@ Prado.WebUI.TValidationSummary.prototype = Prado.WebUI.TBaseValidator = Class.create(); Prado.WebUI.TBaseValidator.prototype = { + enabled : true, + visible : false, + isValid : true, + options : {}, + _isObserving : {}, + group : null, + manager : null, + message : null, + /** * * options['ID']* Validator ID, e.g. span with message @@ -574,8 +561,8 @@ Prado.WebUI.TBaseValidator.prototype = * options['ValidationGroup'] Validation group * options['ControlCssClass'] Css class to use on the input upon error * options['OnValidate'] Function to call immediately after validation - * options['OnValidationSuccess'] Function to call upon after successful validation - * options['OnValidationError'] Function to call upon after error in validation. + * options['OnSuccess'] Function to call upon after successful validation + * options['OnError'] Function to call upon after error in validation. * options['ObserveChanges'] True to observe changes in input * */ @@ -585,23 +572,12 @@ Prado.WebUI.TBaseValidator.prototype = options.OnSuccess = options.OnSuccess || Prototype.emptyFunction; options.OnError = options.OnError || Prototype.emptyFunction; */ - - this.enabled = true; - this.visible = false; - this.isValid = true; - this._isObserving = {}; - this.group = null; - this.requestDispatched = false; - this.options = options; this.control = $(options.ControlToValidate); this.message = $(options.ID); - if(this.control && this.message) - { - this.group = options.ValidationGroup; + this.group = options.ValidationGroup; - this.manager = Prado.Validation.addValidator(options.FormID, this); - } + this.manager = Prado.Validation.addValidator(options.FormID, this); }, /** @@ -623,8 +599,6 @@ Prado.WebUI.TBaseValidator.prototype = if(this.options.FocusOnError && !this.isValid ) Prado.Element.focus(this.options.FocusElementID); - - this.visible = true; }, refreshControlAndMessage : function() @@ -676,21 +650,8 @@ Prado.WebUI.TBaseValidator.prototype = */ validate : function(invoker) { - //try to find the control. - if(!this.control) - this.control = $(this.options.ControlToValidate); - - if(!this.control) - { - this.isValid = true; - return this.isValid; - } - if(typeof(this.options.OnValidate) == "function") - { - if(this.requestDispatched == false) - this.options.OnValidate(this, invoker); - } + this.options.OnValidate(this, invoker); if(this.enabled) this.isValid = this.evaluateIsValid(); @@ -699,26 +660,20 @@ Prado.WebUI.TBaseValidator.prototype = if(this.isValid) { - if(typeof(this.options.OnValidationSuccess) == "function") + if(typeof(this.options.OnSuccess) == "function") { - if(this.requestDispatched == false) - { - this.refreshControlAndMessage(); - this.options.OnValidationSuccess(this, invoker); - } + this.refreshControlAndMessage(); + this.options.OnSuccess(this, invoker); } else this.updateControl(); } else { - if(typeof(this.options.OnValidationError) == "function") + if(typeof(this.options.OnError) == "function") { - if(this.requestDispatched == false) - { - this.refreshControlAndMessage(); - this.options.OnValidationError(this, invoker) - } + this.refreshControlAndMessage(); + this.options.OnError(this, invoker); } else this.updateControl(); @@ -1125,51 +1080,6 @@ Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator, } }); -/** - * Uses callback request to perform validation. - */ -Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator, -{ - validatingValue : null, - - /** - * Calls custom validation function. - */ - evaluateIsValid : function() - { - value = this.getValidationValue(); - if(!this.requestDispatched && value != this.validatingValue) - { - this.validatingValue = value; - request = new Prado.CallbackRequest(this.options.EventTarget, this.options); - 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; - }, - - callbackOnSuccess : function(request, data) - { - this.isValid = data; - this.requestDispatched = false; - if(typeof(this.options.onSuccess) == "function") - this.options.onSuccess(request,data); - Prado.Validation.validate(this.options.FormID, this.group,null); - }, - - callbackOnFailure : function(request, data) - { - this.requestDispatched = false; - if(typeof(this.options.onFailure) == "function") - this.options.onFailure(request,data); - } -}); - /** * TRangeValidator tests whether an input value is within a specified range. * -- cgit v1.2.3