From 9277d12fc0052efacbeed7cf9aaeea608e5f6108 Mon Sep 17 00:00:00 2001
From: Igor Minar
Date: Tue, 13 Mar 2012 00:29:10 -0700
Subject: fix(forms): lowercase all validation error keys
---
src/directive/input.js | 156 ++++++++++++++++++++++++------------------------
src/directive/select.js | 2 +-
2 files changed, 79 insertions(+), 79 deletions(-)
(limited to 'src')
diff --git a/src/directive/input.js b/src/directive/input.js
index 1ed1442f..fee7a082 100644
--- a/src/directive/input.js
+++ b/src/directive/input.js
@@ -15,12 +15,12 @@ var inputType = {
*
* @param {string} ng-model Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
- * @param {string=} required Sets `REQUIRED` validation error key if the value is not entered.
- * @param {number=} ng-minlength Sets `MINLENGTH` validation error key if the value is shorter than
+ * @param {string=} required Sets `required` validation error key if the value is not entered.
+ * @param {number=} ng-minlength Sets `minlength` validation error key if the value is shorter than
* minlength.
- * @param {number=} ng-maxlength Sets `MAXLENGTH` validation error key if the value is longer than
+ * @param {number=} ng-maxlength Sets `maxlength` validation error key if the value is longer than
* maxlength.
- * @param {string=} ng-pattern Sets `PATTERN` validation error key if the value does not match the
+ * @param {string=} ng-pattern Sets `pattern` validation error key if the value does not match the
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
* patterns defined as scope expressions.
* @param {string=} ng-change Angular expression to be executed when input changes due to user
@@ -38,16 +38,16 @@ var inputType = {
@@ -77,19 +77,19 @@ var inputType = {
* @name angular.module.ng.$compileProvider.directive.input.number
*
* @description
- * Text input with number validation and transformation. Sets the `NUMBER` validation
+ * Text input with number validation and transformation. Sets the `number` validation
* error if not a valid number.
*
* @param {string} ng-model Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
- * @param {string=} min Sets the `MIN` validation error key if the value entered is less then `min`.
- * @param {string=} max Sets the `MAX` validation error key if the value entered is greater then `min`.
- * @param {string=} required Sets `REQUIRED` validation error key if the value is not entered.
- * @param {number=} ng-minlength Sets `MINLENGTH` validation error key if the value is shorter than
+ * @param {string=} min Sets the `min` validation error key if the value entered is less then `min`.
+ * @param {string=} max Sets the `max` validation error key if the value entered is greater then `min`.
+ * @param {string=} required Sets `required` validation error key if the value is not entered.
+ * @param {number=} ng-minlength Sets `minlength` validation error key if the value is shorter than
* minlength.
- * @param {number=} ng-maxlength Sets `MAXLENGTH` validation error key if the value is longer than
+ * @param {number=} ng-maxlength Sets `maxlength` validation error key if the value is longer than
* maxlength.
- * @param {string=} ng-pattern Sets `PATTERN` validation error key if the value does not match the
+ * @param {string=} ng-pattern Sets `pattern` validation error key if the value does not match the
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
* patterns defined as scope expressions.
* @param {string=} ng-change Angular expression to be executed when input changes due to user
@@ -106,15 +106,15 @@ var inputType = {
@@ -145,17 +145,17 @@ var inputType = {
* @name angular.module.ng.$compileProvider.directive.input.url
*
* @description
- * Text input with URL validation. Sets the `URL` validation error key if the content is not a
+ * Text input with URL validation. Sets the `url` validation error key if the content is not a
* valid URL.
*
* @param {string} ng-model Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
- * @param {string=} required Sets `REQUIRED` validation error key if the value is not entered.
- * @param {number=} ng-minlength Sets `MINLENGTH` validation error key if the value is shorter than
+ * @param {string=} required Sets `required` validation error key if the value is not entered.
+ * @param {number=} ng-minlength Sets `minlength` validation error key if the value is shorter than
* minlength.
- * @param {number=} ng-maxlength Sets `MAXLENGTH` validation error key if the value is longer than
+ * @param {number=} ng-maxlength Sets `maxlength` validation error key if the value is longer than
* maxlength.
- * @param {string=} ng-pattern Sets `PATTERN` validation error key if the value does not match the
+ * @param {string=} ng-pattern Sets `pattern` validation error key if the value does not match the
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
* patterns defined as scope expressions.
* @param {string=} ng-change Angular expression to be executed when input changes due to user
@@ -171,7 +171,7 @@ var inputType = {
@@ -210,17 +210,17 @@ var inputType = {
* @name angular.module.ng.$compileProvider.directive.input.email
*
* @description
- * Text input with email validation. Sets the `EMAIL` validation error key if not a valid email
+ * Text input with email validation. Sets the `email` validation error key if not a valid email
* address.
*
* @param {string} ng-model Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
- * @param {string=} required Sets `REQUIRED` validation error key if the value is not entered.
- * @param {number=} ng-minlength Sets `MINLENGTH` validation error key if the value is shorter than
+ * @param {string=} required Sets `required` validation error key if the value is not entered.
+ * @param {number=} ng-minlength Sets `minlength` validation error key if the value is shorter than
* minlength.
- * @param {number=} ng-maxlength Sets `MAXLENGTH` validation error key if the value is longer than
+ * @param {number=} ng-maxlength Sets `maxlength` validation error key if the value is longer than
* maxlength.
- * @param {string=} ng-pattern Sets `PATTERN` validation error key if the value does not match the
+ * @param {string=} ng-pattern Sets `pattern` validation error key if the value does not match the
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
* patterns defined as scope expressions.
*
@@ -234,16 +234,16 @@ var inputType = {
@@ -384,10 +384,10 @@ function textInputType(scope, element, attr, ctrl) {
var validate = function(regexp, value) {
if (isEmpty(value) || regexp.test(value)) {
- ctrl.$setValidity('PATTERN', true);
+ ctrl.$setValidity('pattern', true);
return value;
} else {
- ctrl.$setValidity('PATTERN', false);
+ ctrl.$setValidity('pattern', false);
return undefined;
}
};
@@ -418,10 +418,10 @@ function textInputType(scope, element, attr, ctrl) {
var minlength = parseInt(attr.ngMinlength, 10);
var minLengthValidator = function(value) {
if (!isEmpty(value) && value.length < minlength) {
- ctrl.$setValidity('MINLENGTH', false);
+ ctrl.$setValidity('minlength', false);
return undefined;
} else {
- ctrl.$setValidity('MINLENGTH', true);
+ ctrl.$setValidity('minlength', true);
return value;
}
};
@@ -435,10 +435,10 @@ function textInputType(scope, element, attr, ctrl) {
var maxlength = parseInt(attr.ngMaxlength, 10);
var maxLengthValidator = function(value) {
if (!isEmpty(value) && value.length > maxlength) {
- ctrl.$setValidity('MAXLENGTH', false);
+ ctrl.$setValidity('maxlength', false);
return undefined;
} else {
- ctrl.$setValidity('MAXLENGTH', true);
+ ctrl.$setValidity('maxlength', true);
return value;
}
};
@@ -454,10 +454,10 @@ function numberInputType(scope, element, attr, ctrl) {
ctrl.$parsers.push(function(value) {
var empty = isEmpty(value);
if (empty || NUMBER_REGEXP.test(value)) {
- ctrl.$setValidity('NUMBER', true);
+ ctrl.$setValidity('number', true);
return value === '' ? null : (empty ? value : parseFloat(value));
} else {
- ctrl.$setValidity('NUMBER', false);
+ ctrl.$setValidity('number', false);
return undefined;
}
});
@@ -470,10 +470,10 @@ function numberInputType(scope, element, attr, ctrl) {
var min = parseFloat(attr.min);
var minValidator = function(value) {
if (!isEmpty(value) && value < min) {
- ctrl.$setValidity('MIN', false);
+ ctrl.$setValidity('min', false);
return undefined;
} else {
- ctrl.$setValidity('MIN', true);
+ ctrl.$setValidity('min', true);
return value;
}
};
@@ -486,10 +486,10 @@ function numberInputType(scope, element, attr, ctrl) {
var max = parseFloat(attr.max);
var maxValidator = function(value) {
if (!isEmpty(value) && value > max) {
- ctrl.$setValidity('MAX', false);
+ ctrl.$setValidity('max', false);
return undefined;
} else {
- ctrl.$setValidity('MAX', true);
+ ctrl.$setValidity('max', true);
return value;
}
};
@@ -501,10 +501,10 @@ function numberInputType(scope, element, attr, ctrl) {
ctrl.$formatters.push(function(value) {
if (isEmpty(value) || isNumber(value)) {
- ctrl.$setValidity('NUMBER', true);
+ ctrl.$setValidity('number', true);
return value;
} else {
- ctrl.$setValidity('NUMBER', false);
+ ctrl.$setValidity('number', false);
return undefined;
}
});
@@ -515,10 +515,10 @@ function urlInputType(scope, element, attr, ctrl) {
var urlValidator = function(value) {
if (isEmpty(value) || URL_REGEXP.test(value)) {
- ctrl.$setValidity('URL', true);
+ ctrl.$setValidity('url', true);
return value;
} else {
- ctrl.$setValidity('URL', false);
+ ctrl.$setValidity('url', false);
return undefined;
}
};
@@ -532,10 +532,10 @@ function emailInputType(scope, element, attr, ctrl) {
var emailValidator = function(value) {
if (isEmpty(value) || EMAIL_REGEXP.test(value)) {
- ctrl.$setValidity('EMAIL', true);
+ ctrl.$setValidity('email', true);
return value;
} else {
- ctrl.$setValidity('EMAIL', false);
+ ctrl.$setValidity('email', false);
return undefined;
}
};
@@ -600,12 +600,12 @@ function checkboxInputType(scope, element, attr, ctrl) {
*
* @param {string} ng-model Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
- * @param {string=} required Sets `REQUIRED` validation error key if the value is not entered.
- * @param {number=} ng-minlength Sets `MINLENGTH` validation error key if the value is shorter than
+ * @param {string=} required Sets `required` validation error key if the value is not entered.
+ * @param {number=} ng-minlength Sets `minlength` validation error key if the value is shorter than
* minlength.
- * @param {number=} ng-maxlength Sets `MAXLENGTH` validation error key if the value is longer than
+ * @param {number=} ng-maxlength Sets `maxlength` validation error key if the value is longer than
* maxlength.
- * @param {string=} ng-pattern Sets `PATTERN` validation error key if the value does not match the
+ * @param {string=} ng-pattern Sets `pattern` validation error key if the value does not match the
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
* patterns defined as scope expressions.
* @param {string=} ng-change Angular expression to be executed when input changes due to user
@@ -624,12 +624,12 @@ function checkboxInputType(scope, element, attr, ctrl) {
*
* @param {string} ng-model Assignable angular expression to data-bind to.
* @param {string=} name Property name of the form under which the control is published.
- * @param {string=} required Sets `REQUIRED` validation error key if the value is not entered.
- * @param {number=} ng-minlength Sets `MINLENGTH` validation error key if the value is shorter than
+ * @param {string=} required Sets `required` validation error key if the value is not entered.
+ * @param {number=} ng-minlength Sets `minlength` validation error key if the value is shorter than
* minlength.
- * @param {number=} ng-maxlength Sets `MAXLENGTH` validation error key if the value is longer than
+ * @param {number=} ng-maxlength Sets `maxlength` validation error key if the value is longer than
* maxlength.
- * @param {string=} ng-pattern Sets `PATTERN` validation error key if the value does not match the
+ * @param {string=} ng-pattern Sets `pattern` validation error key if the value does not match the
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
* patterns defined as scope expressions.
* @param {string=} ng-change Angular expression to be executed when input changes due to user
@@ -646,13 +646,13 @@ function checkboxInputType(scope, element, attr, ctrl) {
@@ -662,9 +662,9 @@ function checkboxInputType(scope, element, attr, ctrl) {
myForm.lastName.$valid = {{myForm.lastName.$valid}}
myForm.userName.$error = {{myForm.lastName.$error}}
myForm.$valid = {{myForm.$valid}}
- myForm.$error.REQUIRED = {{!!myForm.$error.REQUIRED}}
- myForm.$error.MINLENGTH = {{!!myForm.$error.MINLENGTH}}
- myForm.$error.MAXLENGTH = {{!!myForm.$error.MAXLENGTH}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+ myForm.$error.minlength = {{!!myForm.$error.minlength}}
+ myForm.$error.maxlength = {{!!myForm.$error.maxlength}}
@@ -692,7 +692,7 @@ function checkboxInputType(scope, element, attr, ctrl) {
input('user.last').enter('xx');
expect(binding('user')).toEqual('{"name":"guest"}');
expect(binding('myForm.lastName.$valid')).toEqual('false');
- expect(binding('myForm.lastName.$error')).toMatch(/MINLENGTH/);
+ expect(binding('myForm.lastName.$error')).toMatch(/minlength/);
expect(binding('myForm.$valid')).toEqual('false');
});
@@ -701,7 +701,7 @@ function checkboxInputType(scope, element, attr, ctrl) {
expect(binding('user'))
.toEqual('{"name":"guest"}');
expect(binding('myForm.lastName.$valid')).toEqual('false');
- expect(binding('myForm.lastName.$error')).toMatch(/MAXLENGTH/);
+ expect(binding('myForm.lastName.$error')).toMatch(/maxlength/);
expect(binding('myForm.$valid')).toEqual('false');
});
@@ -769,28 +769,28 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', 'ngModel',
*
* This method should be called by validators - i.e. the parser or formatter functions.
*
- * @param {string} validationToken Name of the validator.
+ * @param {string} validationErrorKey Name of the validator.
* @param {boolean} isValid Whether the current state is valid (true) or invalid (false).
*/
- this.$setValidity = function(validationToken, isValid) {
+ this.$setValidity = function(validationErrorKey, isValid) {
- if (!isValid && this.$error[validationToken]) return;
- if (isValid && !this.$error[validationToken]) return;
+ if (!isValid && this.$error[validationErrorKey]) return;
+ if (isValid && !this.$error[validationErrorKey]) return;
if (isValid) {
- delete this.$error[validationToken];
+ delete this.$error[validationErrorKey];
if (equals(this.$error, {})) {
this.$valid = true;
this.$invalid = false;
}
} else {
- this.$error[validationToken] = true;
+ this.$error[validationErrorKey] = true;
this.$invalid = true;
this.$valid = false;
}
if (this.$form) {
- this.$form.$setValidity(validationToken, isValid, this);
+ this.$form.$setValidity(validationErrorKey, isValid, this);
}
};
@@ -1058,10 +1058,10 @@ var requiredDirective = [function() {
var validator = function(value) {
if (attr.required && (isEmpty(value) || value === false)) {
- ctrl.$setValidity('REQUIRED', false);
+ ctrl.$setValidity('required', false);
return;
} else {
- ctrl.$setValidity('REQUIRED', true);
+ ctrl.$setValidity('required', true);
return value;
}
};
@@ -1096,13 +1096,13 @@ var requiredDirective = [function() {
diff --git a/src/directive/select.js b/src/directive/select.js
index 1c320151..9ea0186d 100644
--- a/src/directive/select.js
+++ b/src/directive/select.js
@@ -140,7 +140,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
// required validator
if (multiple && (attr.required || attr.ngRequired)) {
var requiredValidator = function(value) {
- ctrl.$setValidity('REQUIRED', !attr.required || (value && value.length));
+ ctrl.$setValidity('required', !attr.required || (value && value.length));
return value;
};
--
cgit v1.2.3