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

Cannot assign empty string value to select option #1814

spacejack opened this Issue Apr 26, 2017 · 1 comment


None yet
2 participants
Copy link

spacejack commented Apr 26, 2017

The following hyperscript will not set the select option value to ''

m('select', m('option', {value: ''}, 'Choose...'))

Instead, the value of that option will be 'Choose...'

jsbin demo comparing behaviour of plain HTML and Mithril:,js,output


This comment has been minimized.

Copy link

spacejack commented Apr 27, 2017

I think it comes down to this line:

It's tricky to solve though because of that Chrome hack. I think while the option element is built, it has no children (the text content) and therefore its value is == ''. It's only after the text child is added that the value will be different from ''. I tried changing the comparison to === but it doesn't seem to work; I suppose the value is an empty string by default.

I wonder if that Chrome hack is still necessary. Removing that line makes the test pass.

EDIT: Not sure, but maybe this would work:

if (vnode.tag === "option" && key === "value" && old != null && vnode.dom.value == value) return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment