Closed
Bug 1203668
Opened 9 years ago
Closed 9 years ago
changing the value of a select to a value that matches none of the options should put it in a "no option selected" state even when it's a combobox (size=1)
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla46
Tracking | Status | |
---|---|---|
firefox46 | --- | fixed |
People
(Reporter: thsilva, Assigned: MatsPalmgren_bugz)
References
Details
(Keywords: dev-doc-complete, site-compat)
Attachments
(2 files, 2 obsolete files)
3.35 KB,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
982 bytes,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Steps to reproduce:
Enter in:
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_select_value
And change this line:
document.getElementById("mySelect").value = "banana";
with this one:
document.getElementById("mySelect").value = "banasdana";
Actual results:
The selected value still the first value.
Expected results:
In:
http://www.w3schools.com/jsref/prop_select_value.asp
Specifies the value of an <option> element in a drop-down list that should get selected. If the value does not exist, the drop-down list will display an empty option
"If the value does not exist, the drop-down list will display an empty option"
I was expecting an empty option and not the first value
Assignee | ||
Comment 1•9 years ago
|
||
https://html.spec.whatwg.org/multipage/forms.html#the-select-element
"
On setting, the value attribute must set the selectedness of all the option elements
in the list of options to false, and then the first option element in the list of options,
in tree order, whose value is equal to the given new value, if any, must have its
selectedness set to true and its dirtiness set to true.
NOTE: This can result in no element having a selectedness set to true even in the case of
the select element having no multiple attribute and a display size of 1.
"
Other UAs seems to implement it correctly: Chrome, Safari, IE.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Version: 37 Branch → unspecified
Assignee | ||
Comment 3•9 years ago
|
||
Reporter | ||
Comment 4•9 years ago
|
||
You are fast. tks Mats
Assignee | ||
Comment 5•9 years ago
|
||
Comment on attachment 8659598 [details] [diff] [review]
part 1
The failures in the Try run looks like it's unrelated.
Source link for more context:
http://mxr.mozilla.org/mozilla-central/source/dom/html/HTMLSelectElement.cpp?rev=e9bb1fc9977a#1189
Attachment #8659598 -
Flags: review?(bzbarsky)
Comment 6•9 years ago
|
||
Comment on attachment 8659598 [details] [diff] [review]
part 1
Right now I believe we have the invariant that some option is always selected in a combobox. There's other code in HTMLSelectElement, and I'm pretty sure in combobox control frame, that depends on that invariant.
Which parts of this code have you audited and why is it ok with the invariant change? What is the actual UI behavior (e.g. if you click the combobox to see the dropdown, or tab to it and use arrow keys to change the value) that results in this state?
Flags: needinfo?(mats)
Attachment #8659598 -
Flags: review?(bzbarsky)
Updated•9 years ago
|
Summary: changing the value of a select → changing the value of a select to a value that matches none of the options should put it in a "no option selected" state even when it's a combobox (size=1)
Assignee | ||
Comment 7•9 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #6)
> Right now I believe we have the invariant that some option is always
> selected in a combobox.
I think you're mistaken. Does this example show that we do NOT have
such an invariant?
data:text/html,<select size=1 onfocus="this.selectedIndex=-1"><option>hello
> There's other code in HTMLSelectElement, and I'm
> pretty sure in combobox control frame, that depends on that invariant.
Can you point out the places you know of, if any?
> Which parts of this code have you audited and why is it ok with the
> invariant change?
None, because I believe we do not have such an invariant (the example
above deselects the option also in FF 3.6, so at least we haven't had
this invariant for a very long time).
> What is the actual UI behavior (e.g. if you click the
> combobox to see the dropdown,
Clicking it shows the dropdown menu as usual, with no option highlighted.
If you move the mouse over the menu it highlights the option under the
mouse as usual. After moving the mouse outside the menu (without
selecting anything) nothing is highlighted. Clicking outside the menu
leaves the combobox state as is, i.e. nothing is selected.
> or tab to it and use arrow keys to change the
> value) that results in this state?
Tabbing to it focus it but doesn't change the value. Using the arrow
keys changes the value as usual, and once you do there is no way to
get back to the unselected state (for the user). (It *should* be
possible to type ESC to undo the value change and thus unselect
all options again but I think we have an open bug on that somewhere,
possibly bug 307345).
(BTW, I'm testing this on Linux. Hopefully other platforms behaves
reasonably similar.)
Flags: needinfo?(mats)
Comment 8•9 years ago
|
||
> Does this example show that we do NOT have such an invariant?
Yes, it does. I'll assume then that whoever made that unselect all options already made things work correctly in that setup.
Comment 9•9 years ago
|
||
Comment on attachment 8659598 [details] [diff] [review]
part 1
r=me
Attachment #8659598 -
Flags: review+
Reporter | ||
Comment 10•9 years ago
|
||
Just another information.
In my case, if you select the first option, the event onchange is not fired.
Assignee | ||
Comment 11•9 years ago
|
||
Right, that's because the first option is already selected so we do not
detect a change. That should be fixed now, i.e. going from nothing
selected to something selected should trigger onchange. Please verify
this in a Nightly build (once the fix shows up there, sometime next week
presumably): https://nightly.mozilla.org/
(and please let us know if you see any other weirdness)
Comment 12•9 years ago
|
||
Assignee | ||
Updated•9 years ago
|
Flags: in-testsuite+
Comment 13•9 years ago
|
||
Backed out in https://hg.mozilla.org/integration/mozilla-inbound/rev/3de175bd4e83 for a variety pack of mochitest-chrome failures and timeouts, https://treeherder.mozilla.org/logviewer.html#?job_id=13997355&repo=mozilla-inbound
Comment 14•9 years ago
|
||
And, though nobody wants to get caught in the Gu, https://treeherder.mozilla.org/logviewer.html#?job_id=13997685&repo=mozilla-inbound
Assignee | ||
Comment 15•9 years ago
|
||
This fixes the mochitest failures.
https://treeherder.mozilla.org/#/jobs?repo=try&revision=8290703986d0
Attachment #8660357 -
Flags: review?(bzbarsky)
Assignee | ||
Updated•9 years ago
|
Attachment #8659598 -
Attachment description: wip → part 1
Assignee | ||
Comment 16•9 years ago
|
||
This should fix the dependency in this bug in Gaia code, which caused
the "Gu" failures. I don't know how to submit this patch to Try for
testing though. Any hints would be appreciated.
Assignee | ||
Comment 17•9 years ago
|
||
Note: untested since I don't know to submit Gaia patches to Try.
It appears tzSelect() depends on this bug, i.e. setting a bogus value
on a <select> leaves the current value unchanged rather than the new
behavior which is to deselect all options. I don't know what the
real fix is for this function, but this should emulate the old
<select> behavior I think.
Attachment #8660358 -
Attachment is obsolete: true
Attachment #8660359 -
Flags: review?(fabien)
Comment 18•9 years ago
|
||
Mats, https://wiki.mozilla.org/ReleaseEngineering/TryServer#Using_a_custom_Gaia has directions for doing a try push with a custom Gaia. Basically, you need to fork Gaia on github, make your changes, push them to your github fork on some branch, then point try to that changeset as the Gaia to use.
Comment 19•9 years ago
|
||
Comment on attachment 8660357 [details] [diff] [review]
part 2 - Fix dependency on this bug in devtools code
r=me
Attachment #8660357 -
Flags: review?(bzbarsky) → review+
Assignee | ||
Comment 21•9 years ago
|
||
It might take quite a while before I have time to spend on this bug again.
Jet, can you perhaps find someone that works on Gaia to reivew+test+land
part 3? Once that is done we can land part 1 and 2.
Flags: needinfo?(bugs)
Comment 22•9 years ago
|
||
Tim: can you help get the "part3-gaia" patch landed per comment 21? Thanks!
Flags: needinfo?(bugs) → needinfo?(timdream)
Comment 23•9 years ago
|
||
Interesting. Why would the value not actually exist in the <select> list when we construct the list?
This should be another bug to fix (and arguably might not be a bug blocking this fix.)
I'll do that tomorrow (keeping needinfo).
Comment 24•9 years ago
|
||
As for the patch itself, to keep the old behavior, it make more sense to set selectedIndex to 0 when it's -1 instead of remembering and set the old index?
I don't think -1 and the empty value is ever expected in the rest of the file, so that's probably the safer approach too.
Comment 25•9 years ago
|
||
... but again, there is a Gu test failure.
Comment 26•9 years ago
|
||
Filed and pull request & try submitted in bug 1218677.
Flags: needinfo?(timdream)
Assignee | ||
Comment 27•9 years ago
|
||
Comment on attachment 8660359 [details] [diff] [review]
part3-gaia
(this part will land in bug 1218677)
Attachment #8660359 -
Attachment is obsolete: true
Attachment #8660359 -
Flags: review?(kaze)
Comment 29•9 years ago
|
||
I found a workaround for this problem.
If you are not sure if the assigned value can be found in the listbox use jquery:
$('#listbox1').val('TestValue');
Using this syntax leads to the correct selectedIndex -1 if the assigned value doesn't match.
Comment 30•9 years ago
|
||
Comment 31•9 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/a64dd62f4c12
https://hg.mozilla.org/mozilla-central/rev/81df08547187
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox46:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla46
OS: Unspecified → All
Hardware: Unspecified → All
Version: unspecified → Trunk
Comment 32•9 years ago
|
||
This is going to break sites (it broke one of mine at https://mnoorenberghe.github.io/bz-dependency-buglist/) so marking site-compat. I thought only Safari had this unusual unselected behaviour but I guess it's the way all browsers are going…
In my case I assumed that if none of the options are selected then the first option would be by default which is no longer true.
Keywords: site-compat
Comment 33•9 years ago
|
||
> I thought only Safari had this unusual unselected behaviour
Per comment 1, everyone that isn't Firefox did. So this will only break sites that already didn't work in every other browser...
> In my case I assumed that if none of the options are selected then the first option would be by default
By default, yes. Testcase:
data:text/html,<select><option>a<option>b
This bug was about what happens when the page then explicitly sets value to something that matches none of the options.
Comment 34•9 years ago
|
||
(In reply to Boris Zbarsky [:bz] from comment #33)
> > I thought only Safari had this unusual unselected behaviour
>
> Per comment 1, everyone that isn't Firefox did. So this will only break
> sites that already didn't work in every other browser...
I think this is more recent behaviour for IE (though I code be wrong) and could still break sites with different code for Gecko.
> > In my case I assumed that if none of the options are selected then the first option would be by default
>
> By default, yes. Testcase:
>
> data:text/html,<select><option>a<option>b
>
> This bug was about what happens when the page then explicitly sets value to
> something that matches none of the options.
Yeah, sorry, I realized after commenting that this was due to how my code worked and was a step removed from this change but I decided not to comment to reduce spam on the bug.
Keywords: dev-doc-needed
Reporter | ||
Comment 35•9 years ago
|
||
This is not a recent behavior in IE. I have an application with more than 10 years that works in IE with this behavior.
Comment 36•9 years ago
|
||
Just posted the site compatibility doc: https://www.fxsitecompat.com/en-CA/docs/2016/select-value-is-now-properly-updated-when-non-existent-option-is-programmatically-selected/
Comment 37•9 years ago
|
||
Added an entry in:
https://developer.mozilla.org/en-US/Firefox/Releases/46#DOM_HTML_DOM
Keywords: dev-doc-needed → dev-doc-complete
You need to log in
before you can comment on or make changes to this bug.
Description
•