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

Cannot assign empty string value to select option #1814

Closed
spacejack opened this issue Apr 26, 2017 · 1 comment · Fixed by #1828
Closed

Cannot assign empty string value to select option #1814

spacejack opened this issue Apr 26, 2017 · 1 comment · Fixed by #1828
Labels
Type: Bug For bugs and any other unexpected breakage

Comments

@spacejack
Copy link
Contributor

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: https://jsbin.com/zoqajeyoso/edit?html,js,output

@spacejack
Copy link
Contributor Author

spacejack commented Apr 27, 2017

I think it comes down to this line: https://github.com/lhorie/mithril.js/blob/next/render/render.js#L484

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

@dead-claudia dead-claudia added the Type: Bug For bugs and any other unexpected breakage label Apr 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug For bugs and any other unexpected breakage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants