diff --git a/src/jqLite.js b/src/jqLite.js
index 2dd1d6102bae..4b6d3ed39e99 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -556,9 +556,8 @@ function getBooleanAttrName(element, name) {
return booleanAttr && BOOLEAN_ELEMENTS[nodeName_(element)] && booleanAttr;
}
-function getAliasedAttrName(element, name) {
- var nodeName = element.nodeName;
- return (nodeName === 'INPUT' || nodeName === 'TEXTAREA') && ALIASED_ATTR[name];
+function getAliasedAttrName(name) {
+ return ALIASED_ATTR[name];
}
forEach({
diff --git a/src/ng/compile.js b/src/ng/compile.js
index d8ed0c5e0e3d..9802ed55f8d2 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -1077,7 +1077,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
var node = this.$$element[0],
booleanKey = getBooleanAttrName(node, key),
- aliasedKey = getAliasedAttrName(node, key),
+ aliasedKey = getAliasedAttrName(key),
observer = key,
nodeName;
diff --git a/test/ng/directive/validatorsSpec.js b/test/ng/directive/validatorsSpec.js
index 6b20d6e11086..8f603cf306a5 100644
--- a/test/ng/directive/validatorsSpec.js
+++ b/test/ng/directive/validatorsSpec.js
@@ -219,6 +219,24 @@ describe('validators', function() {
expect($rootScope.form.test.$modelValue).toBe('12340');
expect(inputElm).toBeValid();
});
+
+
+ it('should validate on non-input elements', inject(function($compile) {
+ $rootScope.pattern = '\\d{4}';
+ var elm = $compile('')($rootScope);
+ var elmNg = $compile('')($rootScope);
+ var ctrl = elm.controller('ngModel');
+ var ctrlNg = elmNg.controller('ngModel');
+
+ expect(ctrl.$error.pattern).not.toBe(true);
+ expect(ctrlNg.$error.pattern).not.toBe(true);
+
+ ctrl.$setViewValue('12');
+ ctrlNg.$setViewValue('12');
+
+ expect(ctrl.$error.pattern).toBe(true);
+ expect(ctrlNg.$error.pattern).toBe(true);
+ }));
});
@@ -283,6 +301,24 @@ describe('validators', function() {
helper.changeInputValueTo('12345');
expect(ctrl.$isEmpty).toHaveBeenCalledWith('12345');
});
+
+
+ it('should validate on non-input elements', inject(function($compile) {
+ $rootScope.min = 3;
+ var elm = $compile('')($rootScope);
+ var elmNg = $compile('')($rootScope);
+ var ctrl = elm.controller('ngModel');
+ var ctrlNg = elmNg.controller('ngModel');
+
+ expect(ctrl.$error.minlength).not.toBe(true);
+ expect(ctrlNg.$error.minlength).not.toBe(true);
+
+ ctrl.$setViewValue('12');
+ ctrlNg.$setViewValue('12');
+
+ expect(ctrl.$error.minlength).toBe(true);
+ expect(ctrlNg.$error.minlength).toBe(true);
+ }));
});
@@ -453,6 +489,24 @@ describe('validators', function() {
helper.changeInputValueTo('12345');
expect(ctrl.$isEmpty).toHaveBeenCalledWith('12345');
});
+
+
+ it('should validate on non-input elements', inject(function($compile) {
+ $rootScope.max = 3;
+ var elm = $compile('')($rootScope);
+ var elmNg = $compile('')($rootScope);
+ var ctrl = elm.controller('ngModel');
+ var ctrlNg = elmNg.controller('ngModel');
+
+ expect(ctrl.$error.maxlength).not.toBe(true);
+ expect(ctrlNg.$error.maxlength).not.toBe(true);
+
+ ctrl.$setViewValue('1234');
+ ctrlNg.$setViewValue('1234');
+
+ expect(ctrl.$error.maxlength).toBe(true);
+ expect(ctrlNg.$error.maxlength).toBe(true);
+ }));
});
@@ -547,6 +601,7 @@ describe('validators', function() {
expect(inputElm).toBeValid();
});
+
it('should validate emptiness against the viewValue', function() {
var inputElm = helper.compileInput('');
@@ -560,5 +615,23 @@ describe('validators', function() {
helper.changeInputValueTo('12345');
expect(ctrl.$isEmpty).toHaveBeenCalledWith('12345');
});
+
+
+ it('should validate on non-input elements', inject(function($compile) {
+ $rootScope.value = '12';
+ var elm = $compile('')($rootScope);
+ var elmNg = $compile('')($rootScope);
+ var ctrl = elm.controller('ngModel');
+ var ctrlNg = elmNg.controller('ngModel');
+
+ expect(ctrl.$error.required).not.toBe(true);
+ expect(ctrlNg.$error.required).not.toBe(true);
+
+ ctrl.$setViewValue('');
+ ctrlNg.$setViewValue('');
+
+ expect(ctrl.$error.required).toBe(true);
+ expect(ctrlNg.$error.required).toBe(true);
+ }));
});
});