summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts
diff options
context:
space:
mode:
authormikl <>2008-05-27 15:47:17 +0000
committermikl <>2008-05-27 15:47:17 +0000
commit9868f4ec0609bcdf4684df97b8ada90b838807df (patch)
tree28c6bff1685ae76bd18450a4451c05fe4c5fd378 /framework/Web/Javascripts
parent7c41a6bf7f922849d46bb41ac3e60077ee5f6adf (diff)
Added Prado.Validation.validateControl(id) on client side
Diffstat (limited to 'framework/Web/Javascripts')
-rw-r--r--framework/Web/Javascripts/source/prado/validator/validation3.js72
1 files changed, 65 insertions, 7 deletions
diff --git a/framework/Web/Javascripts/source/prado/validator/validation3.js b/framework/Web/Javascripts/source/prado/validator/validation3.js
index 5f08b615..c9dba7a1 100644
--- a/framework/Web/Javascripts/source/prado/validator/validation3.js
+++ b/framework/Web/Javascripts/source/prado/validator/validation3.js
@@ -71,6 +71,8 @@ Prado.Validation = Class.create();
* where <tt>formID</tt> is the HTML form ID, and the optional
* <tt>groupID</tt> if present will only validate the validators
* in a particular group.</p>
+ * <p>Use <code>{@link Prado.Validation.validateControl}(controlClientID)</code>
+ * to trigger validation for a single control.</p>
*
* @object {static} Prado.Validation
*/
@@ -107,6 +109,24 @@ Object.extend(Prado.Validation,
},
/**
+ * Validate all validators of a specific control.
+ * @function {boolean} ?
+ * @param {string} id - ID of DOM element to validate
+ * @return true if all validators are valid or no validators present, false otherwise.
+ */
+ validateControl : function(id)
+ {
+ var formId=this.getForm();
+
+ if (this.managers[formId])
+ {
+ return this.managers[formId].validateControl(id);
+ } else {
+ throw new Error("A validation manager needs to be created first.");
+ }
+ },
+
+ /**
* Return first registered form
* @function {string} ?
* @returns ID of first form.
@@ -209,6 +229,12 @@ Prado.ValidationManager = Class.create();
Prado.ValidationManager.prototype =
{
/**
+ * Hash of registered validators by control's clientID
+ * @var controls
+ */
+ controls: {},
+
+ /**
* Initialize ValidationManager.
* @constructor {protected} ?
* @param {object} options - Options for initialization
@@ -284,6 +310,17 @@ Prado.ValidationManager.prototype =
},
/**
+ * Perform validation for all validators of a single control.
+ * @function {boolean} ?
+ * @param {string} id - ID of DOM element to validate
+ * @return true if all validators are valid or no validators present, false otherwise.
+ */
+ validateControl : function (id)
+ {
+ return this.controls[id] ? this.controls[id].invoke('validate',null).all() : true;
+ },
+
+ /**
* Focus on the first validator that is invalid and options.FocusOnError is true.
* @function ?
* @param {TBaseValidator[]} validators - Array of validator objects
@@ -371,14 +408,17 @@ Prado.ValidationManager.prototype =
*/
addValidator : function(validator)
{
- // Erase any existing validator with same options
- this.validators = this.validators.reject(function(v)
- {
- return (v.options.ID==validator.options.ID);
- });
+ // Remove previously registered validator with same ID
+ // to prevent stale validators created by AJAX updates
+ this.removeValidator(validator);
+
this.validators.push(validator);
if(validator.group && !this.groups.include(validator.group))
this.groups.push(validator.group);
+
+ if (typeof this.controls[validator.control.id] === 'undefined')
+ this.controls[validator.control.id] = Array();
+ this.controls[validator.control.id].push(validator);
},
/**
@@ -392,6 +432,24 @@ Prado.ValidationManager.prototype =
},
/**
+ * Remove a validator from this manager
+ * @function ?
+ * @param {TBaseValidator} validator - Validator object
+ */
+ removeValidator : function(validator)
+ {
+ this.validators = this.validators.reject(function(v)
+ {
+ return (v.options.ID==validator.options.ID);
+ });
+ if (this.controls[validator.control.id])
+ this.controls[validator.control.id].reject( function(v)
+ {
+ return (v.options.ID==validator.options.ID)
+ });
+ },
+
+ /**
* Gets validators with errors.
* If group is set, only validators in that group are returned.
* Otherwhise only validators without a group are returned.
@@ -473,7 +531,7 @@ Prado.WebUI.TValidationSummary.prototype =
initialize : function(options)
{
/**
- * ValidationManager options
+ * Validator options
* @var {object} options
*/
this.options = options;
@@ -705,7 +763,7 @@ Prado.WebUI.TBaseValidator.prototype =
* Initialize TBaseValidator.
* @constructor {protected} ?
* @param {object} options - Options for initialization.
- * @... {string} ID - ID of validation summary element.
+ * @... {string} ID - ID of validator
* @... {string} FormID - ID of form of this manager.
* @... {string} ControlToValidate - ID of control to validate.
* @... {optional string} InitialValue - Initial value of control to validate.