Merge pull request #1106 from epidemian/fix-1091
Fix #1091 Value on select tag not set when options are changed
This commit is contained in:
commit
c55917d21a
2 changed files with 17 additions and 7 deletions
14
mithril.js
14
mithril.js
|
|
@ -727,13 +727,6 @@
|
||||||
cached.children.nodes = []
|
cached.children.nodes = []
|
||||||
}
|
}
|
||||||
|
|
||||||
// edge case: setting value on <select> doesn't work before children
|
|
||||||
// exist, so set it again after children have been created
|
|
||||||
if (data.tag === "select" && "value" in data.attrs) {
|
|
||||||
setAttributes(node, data.tag, {value: data.attrs.value}, {},
|
|
||||||
namespace)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -888,6 +881,13 @@
|
||||||
controllers)
|
controllers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// edge case: setting value on <select> doesn't work before children
|
||||||
|
// exist, so set it again after children have been created/updated
|
||||||
|
if (data.tag === "select" && "value" in data.attrs) {
|
||||||
|
setAttributes(node, data.tag, {value: data.attrs.value}, {},
|
||||||
|
namespace)
|
||||||
|
}
|
||||||
|
|
||||||
if (!isNew && shouldReattach === true && node != null) {
|
if (!isNew && shouldReattach === true && node != null) {
|
||||||
insertNode(parentElement, node, index)
|
insertNode(parentElement, node, index)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1567,5 +1567,15 @@ describe("m.render()", function () {
|
||||||
expect(root.childNodes[0].innerHTML)
|
expect(root.childNodes[0].innerHTML)
|
||||||
.to.equal('<option value="">aaa</option>')
|
.to.equal('<option value="">aaa</option>')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("sets correct <select> value", function () {
|
||||||
|
var root = document.createElement("div")
|
||||||
|
m.render(root, m("select", {value: "b"}, [
|
||||||
|
m("option", {value: "a"}, "aaa"),
|
||||||
|
m("option", {value: "b"}, "bbb")
|
||||||
|
]))
|
||||||
|
// This works only if select value is set after its options exist.
|
||||||
|
expect(root.childNodes[0].value).to.equal("b")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue