summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormikl <>2008-05-27 15:47:17 +0000
committermikl <>2008-05-27 15:47:17 +0000
commit9868f4ec0609bcdf4684df97b8ada90b838807df (patch)
tree28c6bff1685ae76bd18450a4451c05fe4c5fd378
parent7c41a6bf7f922849d46bb41ac3e60077ee5f6adf (diff)
Added Prado.Validation.validateControl(id) on client side
-rw-r--r--HISTORY1
-rw-r--r--framework/Web/Javascripts/source/prado/validator/validation3.js72
2 files changed, 66 insertions, 7 deletions
diff --git a/HISTORY b/HISTORY
index d90fa23a..bf7e0ffb 100644
--- a/HISTORY
+++ b/HISTORY
@@ -5,6 +5,7 @@ BUG: Ticket#841 - Strange output from THttpResponse (Christophe)
BUG: Ticket#847 - getBaseUrl sometimes fails (Christophe)
BUG: Ticket#843 - TDataList alternatinItem issue after changes in rev 2227 (Christophe)
BUG: Ticket#849 - TDatePicker selecting current date problem (Christophe)
+ENH: Added Prado.Validation.validateControl(id) on client side to validate a specific control (Michael)
Version 3.1.2 April 21, 2008
============================
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.