Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 916326c

Browse files
committed
Revert "temp commit to own repository"
This reverts commit 32cc8a0.
1 parent f3445b0 commit 916326c

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

src/validation-common.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ angular
5353
//----
5454
// Public functions declaration
5555
//----------------------------------
56-
57-
function isValidationRequired(validations) {
58-
return validations.indexOf("required") >= 0 || validations.indexOf("requiredselection") >= 0;
59-
}
56+
6057
function defineValidation() {
6158
var self = this;
6259
var customUserRegEx = {};
@@ -94,7 +91,8 @@ angular
9491
var validations = rules.split('|');
9592

9693
if(validations) {
97-
self.bFieldRequired = isValidationRequired(validations) ? true : false;
94+
self.bFieldRequired = (validations.indexOf("required") >= 0) ? true : false;
95+
9896
// loop through all validators of the element
9997
for(var i = 0, ln = validations.length; i < ln; i++) {
10098
var params = validations[i].split(':'); // params[0] is the rule, [1] is the rule extra params
@@ -127,8 +125,7 @@ angular
127125
* @param string message: error message to display
128126
*/
129127
function updateErrorMsg(message, attrs) {
130-
// attrs.obj if set should be a commonObj
131-
var self = (!!attrs && attrs.obj) ? attrs.obj : this;
128+
var self = this;
132129

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

305302
// if error already exist then refresh the error object inside the array, else push it to the array
306303
if(index >= 0) {

src/validation-rules.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,6 @@ angular
538538
type: "regex"
539539
};
540540
break;
541-
case "requiredselection":
542-
validator = {
543-
pattern: "\\S+",
544-
message: "INVALID_REQUIREDSELECTION",
545-
type: "regex"
546-
};
547-
break;
548541
} // switch()
549542

550543
return validator;

src/validation-service.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ angular
2727
validationService.prototype.addValidator = addValidator;
2828
validationService.prototype.checkFormValidity = checkFormValidity;
2929
validationService.prototype.removeValidator = removeValidator;
30-
validationService.prototype.clearValidationSummary = clearValidationSummary;
3130
validationService.prototype.setGlobalOptions = setGlobalOptions;
3231

3332
return validationService;
@@ -74,7 +73,7 @@ angular
7473
attrs = mergeObjects(self.validationAttrs, attrs);
7574

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

8685
self.commonObj.initialize(attrs.scope, attrs.elm, attrs, attrs.ctrl);
8786
attemptToValidate(self, newVal);
88-
}, true); // $watch()
87+
}, true); // $watch()
8988

9089
return self;
91-
} // addValidator()
90+
} // addValidator()
9291

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

116110
if(!!elm && elm.length > 0) {
117111
ctrl.$setTouched(); // make the element as it was touched for CSS
118-
self.commonObj.updateErrorMsg(obj.$validationSummary[i].message, { valid: false, obj: obj.$validationSummary[i].obj, submitted: true });
112+
self.commonObj.updateErrorMsg(obj.$validationSummary[i].message, {valid: false, elm: elm, submitted: true});
119113
}
120114
}
121115
return isValid;

0 commit comments

Comments
 (0)