Skip to content

Commit 1cc0e41

Browse files
committed
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.
1 parent d4ae798 commit 1cc0e41

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

src/jqLite.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ forEach('multiple,selected,checked,disabled,readOnly,required'.split(','), funct
328328
BOOLEAN_ATTR[lowercase(value)] = value;
329329
});
330330
var BOOLEAN_ELEMENTS = {};
331-
forEach('input,select,option,textarea,button'.split(','), function(value) {
331+
forEach('input,select,option,textarea,button,form'.split(','), function(value) {
332332
BOOLEAN_ELEMENTS[uppercase(value)] = true;
333333
});
334334

@@ -394,8 +394,7 @@ forEach({
394394
}
395395
} else {
396396
return (element[name] ||
397-
element.getAttribute(name) !== null &&
398-
(msie < 9 ? element.getAttribute(name) !== '' : true))
397+
(element.attributes.getNamedItem(name)|| noop).specified)
399398
? lowercasedName
400399
: undefined;
401400
}

src/service/compiler.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,19 @@ function $CompileProvider($provide) {
378378
for (var attr, name, nName, value, nAttrs = node.attributes,
379379
j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {
380380
attr = nAttrs[j];
381-
name = attr.name;
382-
nName = directiveNormalize(name.toLowerCase());
383-
attrsMap[nName] = name;
384-
attrs[nName] = value = trim((msie && name == 'href')
381+
if (attr.specified) {
382+
name = attr.name;
383+
nName = directiveNormalize(name.toLowerCase());
384+
attrsMap[nName] = name;
385+
attrs[nName] = value = trim((msie && name == 'href')
385386
? decodeURIComponent(node.getAttribute(name, 2))
386387
: attr.value);
387-
if (isBooleanAttr(node, nName)) {
388-
attrs[nName] = true; // presence means true
388+
if (isBooleanAttr(node, nName)) {
389+
attrs[nName] = true; // presence means true
390+
}
391+
addAttrInterpolateDirective(node, directives, value, nName)
392+
addDirective(directives, nName, 'A', maxPriority);
389393
}
390-
addAttrInterpolateDirective(node, directives, value, nName)
391-
addDirective(directives, nName, 'A', maxPriority);
392394
}
393395

394396
// use class as directive

test/directive/inputSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,29 @@ describe('input', function() {
316316
});
317317

318318

319+
it('should not set readonly or disabled property on ie7', function() {
320+
this.addMatchers({
321+
toBeOff: function(attributeName) {
322+
var actualValue = this.actual.attr(attributeName);
323+
this.message = function() {
324+
return "Attribute '" + attributeName + "' expected to be off but was '" + actualValue +
325+
"' in: " + angular.mock.dump(this.actual);
326+
}
327+
328+
return !actualValue || actualValue == 'false';
329+
}
330+
});
331+
332+
compileInput('<input type="text" ng-model="name" name="alias"/>');
333+
expect(inputElm.prop('readOnly')).toBe(false);
334+
expect(inputElm.prop('disabled')).toBe(false);
335+
336+
expect(inputElm).toBeOff('readOnly');
337+
expect(inputElm).toBeOff('readonly');
338+
expect(inputElm).toBeOff('disabled');
339+
});
340+
341+
319342
it('should cleanup it self from the parent form', function() {
320343
compileInput('<input ng-model="name" name="alias" required>');
321344

test/jqLiteSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ describe('jqLite', function() {
268268
var elm = jqLite('<div class="any">a</div>');
269269
expect(elm.attr('non-existing')).toBeUndefined();
270270
});
271+
272+
it('should return undefined for non-existing attributes on input', function() {
273+
var elm = jqLite('<input>');
274+
expect(elm.attr('readonly')).toBeUndefined();
275+
expect(elm.attr('readOnly')).toBeUndefined();
276+
expect(elm.attr('disabled')).toBeUndefined();
277+
});
271278
});
272279

273280

0 commit comments

Comments
 (0)