55 * @name BsValidationService
66 * @description Core service of this module to provide various default validations.
77 */
8- angular . module ( "bootstrap.angular.validation" ) . factory ( "BsValidationService" , function ( ) {
8+ angular . module ( "bootstrap.angular.validation" ) . factory ( "BsValidationService" , function ( ) {
99 var messages = {
1010 required : "This field is required." ,
1111 email : "Please enter a valid email address." ,
@@ -25,42 +25,30 @@ angular.module("bootstrap.angular.validation").factory("BsValidationService", fu
2525 var ngIncludedURLs = [ ] ;
2626
2727 var genericValidators = {
28- digits : {
29- validator : function ( value ) {
30- return ( / ^ \d + $ / ) . test ( value ) ;
31- }
28+ digits : function ( value ) {
29+ return ( / ^ \d + $ / ) . test ( value ) ;
3230 } ,
33- equalTo : {
34- validator : function ( value , $scope , attr ) {
35- return value === $scope . $eval ( attr . equalTo ) ;
36- }
31+ equalTo : function ( value , $scope , attr ) {
32+ return value === $scope . $eval ( attr . equalTo ) ;
3733 } ,
38- number : {
39- validator : function ( value ) {
40- return ( / ^ - ? (?: \d + | \d { 1 , 3 } (?: , \d { 3 } ) + ) ? (?: \. \d + ) ? $ / ) . test ( value ) ;
41- }
34+ number : function ( value ) {
35+ return ( / ^ - ? (?: \d + | \d { 1 , 3 } (?: , \d { 3 } ) + ) ? (?: \. \d + ) ? $ / ) . test ( value ) ;
4236 } ,
43- min : {
44- validator : function ( value , $scope , attr ) {
45- return parseFloat ( value ) >= parseFloat ( attr . min ) ;
46- }
37+ min : function ( value , $scope , attr ) {
38+ return parseFloat ( value ) >= parseFloat ( attr . min ) ;
4739 } ,
48- max : {
49- validator : function ( value , $scope , attr ) {
50- return parseFloat ( value ) <= parseFloat ( attr . max ) ;
51- }
40+ max : function ( value , $scope , attr ) {
41+ return parseFloat ( value ) <= parseFloat ( attr . max ) ;
5242 } ,
53- length : {
54- validator : function ( value , $scope , attr ) {
55- return value . length === parseInt ( attr . length ) ;
56- }
43+ length : function ( value , $scope , attr ) {
44+ return value . length === parseInt ( attr . length ) ;
5745 }
5846 } ;
5947
6048 var selectors = [ ] ;
6149 var elements = [ "input" , "select" , "textarea" ] ;
6250
63- angular . forEach ( elements , function ( element ) {
51+ angular . forEach ( elements , function ( element ) {
6452 selectors . push ( element + "[ng-model]" ) ;
6553 selectors . push ( element + "[data-ng-model]" ) ;
6654 } ) ;
@@ -73,23 +61,23 @@ angular.module("bootstrap.angular.validation").factory("BsValidationService", fu
7361 * need not a add it for every form element.
7462 * @param $element
7563 */
76- addDirective : function ( $element ) {
64+ addDirective : function ( $element ) {
7765 var validateableElements = $element . findAll ( selector ) ;
7866 validateableElements . attr ( "bs-validation" , "" ) ;
7967 return validateableElements ;
8068 } ,
81- addToNgIncludedURLs : function ( url ) {
69+ addToNgIncludedURLs : function ( url ) {
8270 if ( ngIncludedURLs . indexOf ( url ) === - 1 ) {
8371 ngIncludedURLs . push ( url ) ;
8472 }
8573 } ,
86- addValidator : function ( $scope , $attr , ngModelController , validatorKey ) {
74+ addValidator : function ( $scope , $attr , ngModelController , validatorKey ) {
8775 ngModelController . $validators [ validatorKey ] = function ( modelValue , viewValue ) {
8876 var value = modelValue || viewValue ;
89- return ngModelController . $isEmpty ( value ) || genericValidators [ validatorKey ] . validator ( value , $scope , $attr ) ;
77+ return ngModelController . $isEmpty ( value ) || genericValidators [ validatorKey ] ( value , $scope , $attr ) ;
9078 } ;
9179 } ,
92- checkNgIncludedURL : function ( url ) {
80+ checkNgIncludedURL : function ( url ) {
9381 var index = ngIncludedURLs . indexOf ( url ) ;
9482 if ( index > - 1 ) {
9583 ngIncludedURLs . splice ( index , 1 ) ;
@@ -98,7 +86,7 @@ angular.module("bootstrap.angular.validation").factory("BsValidationService", fu
9886
9987 return false ;
10088 } ,
101- getDefaultMessage : function ( key ) {
89+ getDefaultMessage : function ( key ) {
10290 return messages [ key ] ;
10391 }
10492 } ;
0 commit comments