Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix select option to use empty string value, add tests. #1828

Merged
merged 2 commits into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ module.exports = function($window) {
//setting select[value] to same value while having select open blinks select dropdown in Chrome
if (vnode.tag === "select" && key === "value" && vnode.dom.value == value && vnode.dom === $doc.activeElement) return
//setting option[value] to same value while having select open blinks select dropdown in Chrome
if (vnode.tag === "option" && key === "value" && vnode.dom.value == value) return
if (vnode.tag === "option" && key === "value" && old != null && vnode.dom.value == value) return
// If you assign an input type that is not supported by IE 11 with an assignment expression, an error will occur.
if (vnode.tag === "input" && key === "type") {
element.setAttribute(key, value)
Expand Down
41 changes: 41 additions & 0 deletions render/tests/test-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,47 @@ o.spec("form inputs", function() {
o(select.dom.firstChild.value).equals("")
})

o("option value defaults to textContent unless explicitly set", function() {
var select = {tag: "select", children :[
{tag: "option", text: "aaa"}
]}

render(root, [select])

o(select.dom.firstChild.value).equals("aaa")
o(select.dom.value).equals("aaa")

//test that value changes when content changes
select = {tag: "select", children :[
{tag: "option", text: "bbb"}
]}

render(root, [select])

o(select.dom.firstChild.value).equals("bbb")
o(select.dom.value).equals("bbb")

//test that value can be set to "" in subsequent render
select = {tag: "select", children :[
{tag: "option", attrs: {value: ""}, text: "aaa"}
]}

render(root, [select])

o(select.dom.firstChild.value).equals("")
o(select.dom.value).equals("")

//test that value reverts to textContent when value omitted
select = {tag: "select", children :[
{tag: "option", text: "aaa"}
]}

render(root, [select])

o(select.dom.firstChild.value).equals("aaa")
o(select.dom.value).equals("aaa")
})

o("select yields invalid value without children", function() {
var select = {tag: "select", attrs: {value: "a"}}

Expand Down