bug(ie7): incorrectly set all inputs to disabled

In ie7 all of the input fields are set to readonly and disabled, because ie7 enumerates over all attributes even if the are not declared on the element.
This commit is contained in:
Misko Hevery 2012-03-19 12:20:57 -07:00
parent d4ae7988da
commit 1cc0e4173d
4 changed files with 42 additions and 11 deletions

View file

@ -328,7 +328,7 @@ forEach('multiple,selected,checked,disabled,readOnly,required'.split(','), funct
BOOLEAN_ATTR[lowercase(value)] = value;
});
var BOOLEAN_ELEMENTS = {};
forEach('input,select,option,textarea,button'.split(','), function(value) {
forEach('input,select,option,textarea,button,form'.split(','), function(value) {
BOOLEAN_ELEMENTS[uppercase(value)] = true;
});
@ -394,8 +394,7 @@ forEach({
}
} else {
return (element[name] ||
element.getAttribute(name) !== null &&
(msie < 9 ? element.getAttribute(name) !== '' : true))
(element.attributes.getNamedItem(name)|| noop).specified)
? lowercasedName
: undefined;
}

View file

@ -378,17 +378,19 @@ function $CompileProvider($provide) {
for (var attr, name, nName, value, nAttrs = node.attributes,
j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {
attr = nAttrs[j];
name = attr.name;
nName = directiveNormalize(name.toLowerCase());
attrsMap[nName] = name;
attrs[nName] = value = trim((msie && name == 'href')
if (attr.specified) {
name = attr.name;
nName = directiveNormalize(name.toLowerCase());
attrsMap[nName] = name;
attrs[nName] = value = trim((msie && name == 'href')
? decodeURIComponent(node.getAttribute(name, 2))
: attr.value);
if (isBooleanAttr(node, nName)) {
attrs[nName] = true; // presence means true
if (isBooleanAttr(node, nName)) {
attrs[nName] = true; // presence means true
}
addAttrInterpolateDirective(node, directives, value, nName)
addDirective(directives, nName, 'A', maxPriority);
}
addAttrInterpolateDirective(node, directives, value, nName)
addDirective(directives, nName, 'A', maxPriority);
}
// use class as directive

View file

@ -316,6 +316,29 @@ describe('input', function() {
});
it('should not set readonly or disabled property on ie7', function() {
this.addMatchers({
toBeOff: function(attributeName) {
var actualValue = this.actual.attr(attributeName);
this.message = function() {
return "Attribute '" + attributeName + "' expected to be off but was '" + actualValue +
"' in: " + angular.mock.dump(this.actual);
}
return !actualValue || actualValue == 'false';
}
});
compileInput('<input type="text" ng-model="name" name="alias"/>');
expect(inputElm.prop('readOnly')).toBe(false);
expect(inputElm.prop('disabled')).toBe(false);
expect(inputElm).toBeOff('readOnly');
expect(inputElm).toBeOff('readonly');
expect(inputElm).toBeOff('disabled');
});
it('should cleanup it self from the parent form', function() {
compileInput('<input ng-model="name" name="alias" required>');

View file

@ -268,6 +268,13 @@ describe('jqLite', function() {
var elm = jqLite('<div class="any">a</div>');
expect(elm.attr('non-existing')).toBeUndefined();
});
it('should return undefined for non-existing attributes on input', function() {
var elm = jqLite('<input>');
expect(elm.attr('readonly')).toBeUndefined();
expect(elm.attr('readOnly')).toBeUndefined();
expect(elm.attr('disabled')).toBeUndefined();
});
});