summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/js/debug/validator.js
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/Javascripts/js/debug/validator.js')
-rw-r--r--framework/Web/Javascripts/js/debug/validator.js131
1 files changed, 60 insertions, 71 deletions
diff --git a/framework/Web/Javascripts/js/debug/validator.js b/framework/Web/Javascripts/js/debug/validator.js
index 83453052..179963f4 100644
--- a/framework/Web/Javascripts/js/debug/validator.js
+++ b/framework/Web/Javascripts/js/debug/validator.js
@@ -78,6 +78,7 @@ Object.extend(Prado.Validation,
*/
validate : function(formID, groupID, invoker)
{
+ formID = formID || this.getForm();
if(this.managers[formID])
{
return this.managers[formID].validate(groupID, invoker);
@@ -106,12 +107,23 @@ Object.extend(Prado.Validation,
*/
isValid : function(formID, groupID)
{
+ formID = formID || this.getForm();
if(this.managers[formID])
return this.managers[formID].isValid(groupID);
return true;
},
/**
+ * Reset the validators for a given group.
+ */
+ reset : function(groupID)
+ {
+ var formID = this.getForm();
+ if(this.managers[formID])
+ this.managers[formID].reset(groupID);
+ },
+
+ /**
* Add a new validator to a particular form.
* @param string the form that the validator belongs.
* @param object a validator
@@ -184,102 +196,75 @@ Prado.ValidationManager.prototype =
},
/**
- * Validate the validators managed by this validation manager.
- * @param string only validate validators belonging to a group (optional)
- * @param HTMLElement element that calls for validation
- * @return boolean true if all validators are valid, false otherwise.
+ * Reset all validators in the given group (if group is null, validators without a group are used).
*/
- validate : function(group, invoker)
+ reset : function(group)
{
- if(group)
- return this._validateGroup(group, invoker);
- else
- return this._validateNonGroup(invoker);
+ this.validatorPartition(group)[0].invoke('reset');
+ this.updateSummary(group, true);
},
/**
- * Validate a particular group of validators.
- * @param string ID of the form
+ * Validate the validators managed by this validation manager.
+ * @param string only validate validators belonging to a group (optional)
* @param HTMLElement element that calls for validation
- * @return boolean false if group is not valid, true otherwise.
+ * @return boolean true if all validators are valid, false otherwise.
*/
- _validateGroup: function(groupID, invoker)
+ validate : function(group, source)
{
- var valid = true;
- if(this.groups.include(groupID))
- {
- this.validators.each(function(validator)
- {
- if(validator.group == groupID)
- valid = valid & validator.validate(invoker);
- else
- validator.hide();
- });
- }
- this.updateSummary(groupID, true);
+ var partition = this.validatorPartition(group);
+ var valid = partition[0].invoke('validate', source).all();
+ partition[1].invoke('hide');
+ this.updateSummary(group, true);
return valid;
},
+
/**
- * Validate validators that doesn't belong to any group.
- * @return boolean false if not valid, true otherwise.
- * @param HTMLElement element that calls for validation
+ * @return array[0] validators belong to a group if group is given, otherwise validators
+ * not belongining to any group. array[1] the opposite of array[0].
*/
- _validateNonGroup : function(invoker)
+ validatorPartition : function(group)
{
- var valid = true;
- this.validators.each(function(validator)
- {
- if(!validator.group)
- valid = valid & validator.validate(invoker);
- else
- validator.hide();
- });
- this.updateSummary(null, true);
- return valid;
+ return group ? this.validatorsInGroup(group) : this.validatorsWithoutGroup();
},
/**
- * Gets the state of all the validators, true if they are all valid.
- * @return boolean true if the validators are valid.
+ * @return array validatiors in a given group in first array and
+ * validators not belonging to the group in 2nd array.
*/
- isValid : function(group)
+ validatorsInGroup : function(groupID)
{
- if(group)
- return this._isValidGroup(group);
+ if(this.groups.include(groupID))
+ {
+ return this.validators.partition(function(val)
+ {
+ return val.group == groupID;
+ });
+ }
else
- return this._isValidNonGroup();
+ return [[],[]];
},
/**
- * @return boolean true if all validators not belonging to a group are valid.
+ * @return array validators without any group in first array, and those
+ * with groups in 2nd array.
*/
- _isValidNonGroup : function()
+ validatorsWithoutGroup : function()
{
- var valid = true;
- this.validators.each(function(validator)
+ return this.validators.partition(function(val)
{
- if(!validator.group)
- valid = valid & validator.isValid;
+ return !val.group;
});
- return valid;
},
/**
- * @return boolean true if all validators belonging to the group are valid.
+ * Gets the state of all the validators, true if they are all valid.
+ * @return boolean true if the validators are valid.
*/
- _isValidGroup : function(groupID)
+ isValid : function(group)
{
- var valid = true;
- if(this.groups.include(groupID))
- {
- this.validators.each(function(validator)
- {
- if(validator.group == groupID)
- valid = valid & validator.isValid;
- });
- }
- return valid;
+ return this.validatorPartition(group)[0].pluck('isValid').all();
},
/**
@@ -309,14 +294,10 @@ Prado.ValidationManager.prototype =
*/
getValidatorsWithError : function(group)
{
- var validators = this.validators.findAll(function(validator)
+ return this.validatorPartition(group)[0].findAll(function(validator)
{
- var notValid = !validator.isValid;
- var inGroup = group && validator.group == group;
- var noGroup = validator.group == null;
- return notValid && (inGroup || noGroup);
+ return !validator.isValid;
});
- return validators;
},
/**
@@ -662,9 +643,17 @@ Prado.WebUI.TBaseValidator.prototype =
*/
hide : function()
{
+ this.reset();
+ this.visible = false;
+ },
+
+ /**
+ * Sets isValid = true and updates the validator display.
+ */
+ reset : function()
+ {
this.isValid = true;
this.updateControl();
- this.visible = false;
},
/**