Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "temp commit to own repository"
This reverts commit 32cc8a0.
  • Loading branch information
tlastad committed Apr 7, 2015
commit 916326c084242a1f7f038baa9c5ec193fae86f6d
13 changes: 5 additions & 8 deletions src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ angular
//----
// Public functions declaration
//----------------------------------

function isValidationRequired(validations) {
return validations.indexOf("required") >= 0 || validations.indexOf("requiredselection") >= 0;
}

function defineValidation() {
var self = this;
var customUserRegEx = {};
Expand Down Expand Up @@ -94,7 +91,8 @@ angular
var validations = rules.split('|');

if(validations) {
self.bFieldRequired = isValidationRequired(validations) ? true : false;
self.bFieldRequired = (validations.indexOf("required") >= 0) ? true : false;

// loop through all validators of the element
for(var i = 0, ln = validations.length; i < ln; i++) {
var params = validations[i].split(':'); // params[0] is the rule, [1] is the rule extra params
Expand Down Expand Up @@ -127,8 +125,7 @@ angular
* @param string message: error message to display
*/
function updateErrorMsg(message, attrs) {
// attrs.obj if set should be a commonObj
var self = (!!attrs && attrs.obj) ? attrs.obj : this;
var self = this;

// element name could be defined in the `attrs` or in the self object
var elm = (!!attrs && attrs.elm) ? attrs.elm : self.elm;
Expand Down Expand Up @@ -300,7 +297,7 @@ angular
if(index >= 0 && message === '') {
validationSummary.splice(index, 1);
}else if(message !== '') {
var errorObj = { field: elmName, message: message, obj: self};
var errorObj = { field: elmName, message: message };

// if error already exist then refresh the error object inside the array, else push it to the array
if(index >= 0) {
Expand Down
7 changes: 0 additions & 7 deletions src/validation-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,6 @@ angular
type: "regex"
};
break;
case "requiredselection":
validator = {
pattern: "\\S+",
message: "INVALID_REQUIREDSELECTION",
type: "regex"
};
break;
} // switch()

return validator;
Expand Down
20 changes: 7 additions & 13 deletions src/validation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ angular
validationService.prototype.addValidator = addValidator;
validationService.prototype.checkFormValidity = checkFormValidity;
validationService.prototype.removeValidator = removeValidator;
validationService.prototype.clearValidationSummary = clearValidationSummary;
validationService.prototype.setGlobalOptions = setGlobalOptions;

return validationService;
Expand Down Expand Up @@ -74,7 +73,7 @@ angular
attrs = mergeObjects(self.validationAttrs, attrs);

// watch the element for any value change, validate it once that happen
attrs.scope.$watch(attrs.elmName, function (newVal, oldVal) {
attrs.scope.$watch(attrs.elmName, function (newVal, oldVal) {
if(newVal === undefined && oldVal !== undefined) {
self.commonObj.updateErrorMsg("INVALID_KEY_CHAR", {valid: false, translate: true});
return;
Expand All @@ -85,17 +84,11 @@ angular

self.commonObj.initialize(attrs.scope, attrs.elm, attrs, attrs.ctrl);
attemptToValidate(self, newVal);
}, true); // $watch()
}, true); // $watch()

return self;
} // addValidator()
} // addValidator()

function clearValidationSummary(obj) {
if (typeof obj === "undefined" || typeof obj.$validationSummary === "undefined") {
throw 'checkFormValidity() requires a valid Angular Form or $scope object passed as argument to function properly (ex.: $scope.form1 OR $scope).';
}
obj.$validationSummary = [];
}
/** Is the Form all valid? Loop through Validation Summary to get the answer, if any errors are there then display them and return false
* @param object Angular Form or Scope Object
* @return bool isFormValid
Expand All @@ -110,12 +103,13 @@ angular
// loop through $validationSummary and display errors when found on each field
for(var i = 0, ln = obj.$validationSummary.length; i < ln; i++) {
isValid = false;
elm = obj.$validationSummary[i].obj.elm;
ctrl = obj.$validationSummary[i].obj.ctrl;
elmName = obj.$validationSummary[i].field;
elm = angular.element(document.querySelector('[name="'+elmName+'"]:not([disabled]):not([ng-disabled]'));
ctrl = angular.element(elm).controller('ngModel');

if(!!elm && elm.length > 0) {
ctrl.$setTouched(); // make the element as it was touched for CSS
self.commonObj.updateErrorMsg(obj.$validationSummary[i].message, { valid: false, obj: obj.$validationSummary[i].obj, submitted: true });
self.commonObj.updateErrorMsg(obj.$validationSummary[i].message, {valid: false, elm: elm, submitted: true});
}
}
return isValid;
Expand Down