Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Commit

Permalink
External validation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsamwell committed Jun 17, 2016
1 parent 6f07a03 commit 037ca31
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-auto-validate",
"version": "1.19.4",
"version": "1.19.6",
"description": "An automatic validation module for AngularJS which gets rid of excess html in favour of dynamic element modification to notify the user of validation errors",
"main": "dist/jcs-auto-validate.js",
"keywords": [
Expand Down
8 changes: 4 additions & 4 deletions dist/jcs-auto-validate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* angular-auto-validate - v1.19.4 - 2016-06-16
* angular-auto-validate - v1.19.6 - 2016-06-17
* https://github.com/jonsamwell/angular-auto-validate
* Copyright (c) 2016 Jon Samwell (http://www.jonsamwell.com)
*/
Expand Down Expand Up @@ -1535,8 +1535,7 @@ angular.module('jcs-autoValidate').config(['$provide',

ngModelCtrl.setExternalValidation = function (errorMsgKey, errorMessage, addToModelErrors) {
if (addToModelErrors) {
var collection = ngModelCtrl.$error || ngModelCtrl.$errors;
collection[errorMsgKey] = false;
ngModelCtrl.$setValidity(errorMsgKey, false);
}

ngModelCtrl.externalErrors = ngModelCtrl.externalErrors || {};
Expand All @@ -1546,6 +1545,7 @@ angular.module('jcs-autoValidate').config(['$provide',

ngModelCtrl.removeExternalValidation = function (errorMsgKey, addToModelErrors) {
if (addToModelErrors) {
ngModelCtrl.$setValidity(errorMsgKey, true);
var collection = ngModelCtrl.$error || ngModelCtrl.$errors;
delete collection[errorMsgKey];
}
Expand All @@ -1561,11 +1561,11 @@ angular.module('jcs-autoValidate').config(['$provide',
if (ngModelCtrl.externalErrors) {
var errorCollection = ngModelCtrl.$error || ngModelCtrl.$errors;
angular.forEach(ngModelCtrl.externalErrors, function (value, key) {
ngModelCtrl.$setValidity(key, true);
delete errorCollection[key];
});

ngModelCtrl.externalErrors = {};

validationManager.resetElement(element);
}
};
Expand Down
4 changes: 2 additions & 2 deletions dist/jcs-auto-validate.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-auto-validate",
"version": "1.19.4",
"version": "1.19.6",
"description": "An automatic validation module for AngularJS which gets rid of excess html in favour of dynamic element modification to notify the user of validation errors",
"main": "angular-auto-validate.min.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/config/ngModelDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ angular.module('jcs-autoValidate').config(['$provide',

ngModelCtrl.setExternalValidation = function (errorMsgKey, errorMessage, addToModelErrors) {
if (addToModelErrors) {
var collection = ngModelCtrl.$error || ngModelCtrl.$errors;
collection[errorMsgKey] = false;
ngModelCtrl.$setValidity(errorMsgKey, false);
}

ngModelCtrl.externalErrors = ngModelCtrl.externalErrors || {};
Expand All @@ -74,6 +73,7 @@ angular.module('jcs-autoValidate').config(['$provide',

ngModelCtrl.removeExternalValidation = function (errorMsgKey, addToModelErrors) {
if (addToModelErrors) {
ngModelCtrl.$setValidity(errorMsgKey, true);
var collection = ngModelCtrl.$error || ngModelCtrl.$errors;
delete collection[errorMsgKey];
}
Expand All @@ -89,11 +89,11 @@ angular.module('jcs-autoValidate').config(['$provide',
if (ngModelCtrl.externalErrors) {
var errorCollection = ngModelCtrl.$error || ngModelCtrl.$errors;
angular.forEach(ngModelCtrl.externalErrors, function (value, key) {
ngModelCtrl.$setValidity(key, true);
delete errorCollection[key];
});

ngModelCtrl.externalErrors = {};

validationManager.resetElement(element);
}
};
Expand Down
7 changes: 3 additions & 4 deletions tests/config/ngModelDecorator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@
ngModelController = element.controller('ngModel');
ngModelController.setExternalValidation(errorKey, 'msgKey', true);


expect(ngModelController.$error[errorKey]).to.equal(false);
expect(ngModelController.$error[errorKey]).to.equal(true);
expect(ngModelController.externalErrors[errorKey]).to.equal(false);
});
});
Expand All @@ -192,7 +191,7 @@
ngModelController.setExternalValidation(errorKey, 'msgKey', true);


expect(ngModelController.$error[errorKey]).to.equal(false);
expect(ngModelController.$error[errorKey]).to.equal(true);
expect(ngModelController.externalErrors[errorKey]).to.equal(false);

ngModelController.removeExternalValidation(errorKey, true);
Expand Down Expand Up @@ -220,7 +219,7 @@
ngModelController = element.controller('ngModel');
ngModelController.setExternalValidation(errorKey, 'msgKey', true);

expect(ngModelController.$error[errorKey]).to.equal(false);
expect(ngModelController.$error[errorKey]).to.equal(true);
expect(ngModelController.externalErrors[errorKey]).to.equal(false);

ngModelController.removeAllExternalValidation();
Expand Down
5 changes: 3 additions & 2 deletions tests/testPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ <h1>Not Required</h1>
<script type="text/javascript" src="../src/services/debounce.js"></script>
<script type="text/javascript" src="../src/services/defaultErrorMessageResolver.js"></script>
<script type="text/javascript" src="../src/services/foundation5ElementModifier.js"></script>
<script type="text/javascript" src="../src/services/foundation6ElementModifier.js"></script>
<script type="text/javascript" src="../src/services/validationManager.js"></script>
<script type="text/javascript" src="../src/config/ngSubmitDecorator.js"></script>
<script type="text/javascript" src="../src/config/ngModelDecorator.js"></script>
Expand Down Expand Up @@ -191,7 +192,7 @@ <h1>Not Required</h1>
};

$scope.setExternalError = function (frm) {
frm.setExternalValidation('firstname', undefined, 'hello joe');
frm.setExternalValidation('firstname', "customError", 'hello joe', true);
};

$scope.toggleBS3Icons();
Expand Down Expand Up @@ -313,4 +314,4 @@ <h1>Not Required</h1>
}(angular));
</script>
</body>
</html>
</html>

0 comments on commit 037ca31

Please sign in to comment.