Skip to content

Commit d548357

Browse files
committed
Using $validators in ngModelController introduced in 1.3.0 for validation.
1 parent ce511f9 commit d548357

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ This library solves the pain of various [Bootstrap](getbootstrap.com) + AngularJ
1212
[jQuery like validation](https://jqueryvalidation.org/documentation/)(of course without the jQuery) and using the
1313
Bootstrap's [form validation classes](http://getbootstrap.com/css/#forms-control-validation).
1414

15+
## Compatibility
16+
17+
Minimum AngularJS version required: **1.3.0**. If you are using an older version of AngularJS, please use the version
18+
`0.0.1` of this library but that have some known bugs which are fixed in newer versions.
19+
1520
## Features
1621

1722
**A few things to look out for when playing around**

dist/bootstrap-angular-validation.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/validation.directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ angular.module("bootstrap.angular.validation").directive("bsValidation", ["$inte
120120
});
121121
}
122122

123-
var validators = ["equalTo", "minlength", "maxlength", "min", "max", "number", "digits", "length"];
123+
var validators = ["equalTo", "min", "max", "number", "digits", "length"];
124124
// Register generic custom validators if added to element
125125
angular.forEach(validators, function(key) {
126126
var attrValue = $element.attr(key);

src/services/validation.service.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,9 @@ angular.module("bootstrap.angular.validation").factory("BsValidationService", fu
5454
validator: function(value, $scope, attr) {
5555
return value.length === parseInt(attr.length);
5656
}
57-
},
58-
minlength: {
59-
validator: function(value, $scope, attr) {
60-
return value.length >= parseInt(attr.minlength);
61-
}
62-
},
63-
maxlength: {
64-
validator: function(value, $scope, attr) {
65-
return value.length <= parseInt(attr.maxlength);
66-
}
6757
}
6858
};
6959

70-
function setValidity(key, value, $scope, attr, ngModelController) {
71-
var isValid = ngModelController.$isEmpty(value) || genericValidators[key].validator(value, $scope, attr, ngModelController);
72-
ngModelController.$setValidity(key, isValid);
73-
}
74-
7560
var selectors = [];
7661
var elements = ["input", "select", "textarea"];
7762

@@ -99,12 +84,10 @@ angular.module("bootstrap.angular.validation").factory("BsValidationService", fu
9984
}
10085
},
10186
addValidator: function($scope, $attr, ngModelController, validatorKey) {
102-
var validator = function(value) {
103-
setValidity(validatorKey, value, $scope, $attr, ngModelController);
104-
return value;
87+
ngModelController.$validators[validatorKey] = function (modelValue, viewValue) {
88+
var value = modelValue || viewValue;
89+
return ngModelController.$isEmpty(value) || genericValidators[validatorKey].validator(value, $scope, $attr, ngModelController);
10590
};
106-
107-
ngModelController.$parsers.push(validator);
10891
},
10992
checkNgIncludedURL: function(url) {
11093
var index = ngIncludedURLs.indexOf(url);
@@ -117,9 +100,6 @@ angular.module("bootstrap.angular.validation").factory("BsValidationService", fu
117100
},
118101
getDefaultMessage: function(key) {
119102
return messages[key];
120-
},
121-
setValidity: function(key, value, $scope, attr, ctrl) {
122-
setValidity(key, value, $scope, attr, ctrl);
123103
}
124104
};
125105
});

0 commit comments

Comments
 (0)