Skip to content

Commit

Permalink
Some style fixes. #6
Browse files Browse the repository at this point in the history
  • Loading branch information
sagrawal31 committed Jul 16, 2016
1 parent 493daf7 commit af0ad59
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.idea
node_modules
bower_components
test.sh
2 changes: 1 addition & 1 deletion src/directives/validation.directive.js
Expand Up @@ -92,7 +92,7 @@ angular.module('bootstrap.angular.validation').directive('bsValidation', [
}

if (shouldValidateOnBlur) {
var dewatcher = $scope.$watch(function () {
var dewatcher = $scope.$watch(function() {
return ngModelController.$touched;
}, function(lostFocus) {
if (lostFocus) {
Expand Down
34 changes: 17 additions & 17 deletions src/services/validation.service.js
Expand Up @@ -32,33 +32,33 @@ angular.module('bootstrap.angular.validation').factory('BsValidationService', ['
var ngIncludedURLs = [];

var genericValidators = {
digits: function (value) {
digits: function(value) {
return (/^\d+$/).test(value);
},
equalto: function (value, $scope, attr) {
equalto: function(value, $scope, attr) {
return value + '' === attr.equalto + '';
},
number: function (value) {
number: function(value) {
return (/^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/).test(value);
},
min: function (value, $scope, attr) {
min: function(value, $scope, attr) {
return parseFloat(value) >= parseFloat(attr.min);
},
max: function (value, $scope, attr) {
max: function(value, $scope, attr) {
return parseFloat(value) <= parseFloat(attr.max);
},
length: function (value, $scope, attr) {
length: function(value, $scope, attr) {
return value.length === parseInt(attr.length);
},
strictemail: function (value) {
strictemail: function(value) {
return new RegExp(/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/).test(value);
}
};

var selectors = [];
var elements = ['input', 'select', 'textarea'];

angular.forEach(elements, function (element) {
angular.forEach(elements, function(element) {
selectors.push(element + '[ng-model]');
selectors.push(element + '[data-ng-model]');
});
Expand All @@ -70,13 +70,13 @@ angular.module('bootstrap.angular.validation').factory('BsValidationService', ['
* Search all the input element inside the given DOM element and apply the 'bs-validation' directive so we
* need not a add it for every form element.
*/
getValidators: function () {
getValidators: function() {
var builtIn = ['equalto', 'min', 'max', 'number', 'digits', 'length'];
var additional = Object.keys(genericValidators);
return builtIn.concat(additional);
},

getMeta: function () {
getMeta: function() {
return ['matchName'];
},

Expand All @@ -90,7 +90,7 @@ angular.module('bootstrap.angular.validation').factory('BsValidationService', ['
return metaInformation;
},

addDirective: function ($element) {
addDirective: function($element) {
var validateableElements = $element.find(selector);
validateableElements.attr('bs-validation', '');
return validateableElements;
Expand All @@ -109,20 +109,20 @@ angular.module('bootstrap.angular.validation').factory('BsValidationService', ['
}
},

addToNgIncludedURLs: function (url) {
addToNgIncludedURLs: function(url) {
if (ngIncludedURLs.indexOf(url) === -1) {
ngIncludedURLs.push(url);
}
},

addValidator: function ($scope, $attr, ngModelController, validatorKey) {
ngModelController.$validators[validatorKey] = function (modelValue, viewValue) {
addValidator: function($scope, $attr, ngModelController, validatorKey) {
ngModelController.$validators[validatorKey] = function(modelValue, viewValue) {
var value = modelValue || viewValue;
return ngModelController.$isEmpty(value) || genericValidators[validatorKey](value, $scope, $attr);
};
},

checkNgIncludedURL: function (url) {
checkNgIncludedURL: function(url) {
var index = ngIncludedURLs.indexOf(url);
if (index > -1) {
ngIncludedURLs.splice(index, 1);
Expand Down Expand Up @@ -153,7 +153,7 @@ angular.module('bootstrap.angular.validation').factory('BsValidationService', ['
return validationConfig.getDisplayErrorsAs();
},

getDefaultMessage: function (key) {
getDefaultMessage: function(key) {
return messages[key];
},

Expand Down Expand Up @@ -202,7 +202,7 @@ angular.module('bootstrap.angular.validation').factory('BsValidationService', ['
$formGroupElement.removeClass(validationConfig.successClass);
},

resolveMessage: function ($element, $attr, key) {
resolveMessage: function($element, $attr, key) {
var metaInformation = this.getMetaInformation($element);
var message = $element.attr(key + '-notification') || this.getDefaultMessage(key);

Expand Down

0 comments on commit af0ad59

Please sign in to comment.