Skip to content

Commit eb710ff

Browse files
authored
Merge pull request #38 from sreynen/patch-1
Default type on input set as attribute
2 parents cb8eda8 + 7e404ad commit eb710ff

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

dom-element.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,25 @@ DOMElement.prototype.setAttributeNS =
104104
prefix = name.substr(0, colonPosition)
105105
localName = name.substr(colonPosition + 1)
106106
}
107-
var attributes = this._attributes[namespace] || (this._attributes[namespace] = {})
108-
attributes[localName] = {value: value, prefix: prefix}
107+
if (this.tagName === 'INPUT' && name === 'type') {
108+
this.type = value;
109+
}
110+
else {
111+
var attributes = this._attributes[namespace] || (this._attributes[namespace] = {})
112+
attributes[localName] = {value: value, prefix: prefix}
113+
}
109114
}
110115

111116
DOMElement.prototype.getAttributeNS =
112117
function _Element_getAttributeNS(namespace, name) {
113118
var attributes = this._attributes[namespace];
114119
var value = attributes && attributes[name] && attributes[name].value
120+
if (this.tagName === 'INPUT' && name === 'type') {
121+
return this.type;
122+
}
115123
if (typeof value !== "string") {
116124
return null
117125
}
118-
119126
return value
120127
}
121128

test/test-document.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,19 @@ function testDocument(document) {
326326

327327
test("input has type=text by default", function (assert) {
328328
var elem = document.createElement("input")
329-
assert.equal(elem.type, "text");
329+
assert.equal(elem.getAttribute("type"), "text");
330330
assert.equal(elemString(elem), "<input type=\"text\" />")
331331
assert.end()
332332
})
333333

334+
test("input type=text can be overridden", function (assert) {
335+
var elem = document.createElement("input")
336+
elem.setAttribute("type", "hidden")
337+
assert.equal(elem.getAttribute("type"), "hidden");
338+
assert.equal(elemString(elem), "<input type=\"hidden\" />")
339+
assert.end()
340+
})
341+
334342
test("can set and get attributes", function (assert) {
335343
var elem = document.createElement("div")
336344
assert.equal(elem.getAttribute("foo"), null)

0 commit comments

Comments
 (0)