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:
Leo Horie 2016-06-13 11:13:32 -04:00 committed by GitHub
commit c55917d21a
2 changed files with 17 additions and 7 deletions

View file

@ -727,13 +727,6 @@
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
}
@ -888,6 +881,13 @@
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) {
insertNode(parentElement, node, index)
}

View file

@ -1567,5 +1567,15 @@ describe("m.render()", function () {
expect(root.childNodes[0].innerHTML)
.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")
})
})
})