Bug 53860 - style.display affecting the initial selectedIndex value of a <select> when it's multiple attribute is set programatically
Summary: style.display affecting the initial selectedIndex value of a <select> when it...
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Emil A Eklund
Depends on:
Reported: 2011-02-05 15:17 PST by Darth
Modified: 2011-03-16 11:45 PDT (History)
4 users (show)

See Also:

testcase (885 bytes, text/html)
2011-02-05 15:17 PST, Darth
no flags Details
Patch (5.27 KB, patch)
2011-03-03 15:35 PST, Emil A Eklund
dglazkov: review+
dglazkov: commit-queue-
Details | Formatted Diff | Diff
Patch (5.48 KB, patch)
2011-03-08 14:15 PST, Emil A Eklund
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darth 2011-02-05 15:17:20 PST
Created attachment 81378 [details]

Downstream bug - http://code.google.com/p/chromium/issues/detail?id=71398

See the attached html.
It has a simple <select> element which has a display:none on it.
It does not have multiple=true on it initially, which is set later programmatically onload.

By default single selects as above have a selectedIndex = 0 as per w3c spec.
When this select's mutiple attribute is set to true via javascript, it should retain its selectedIndex = 0.
So converting that select to multiple select should still output selectedIndex = 0.

However this doesn't work as expected in webkit when there is display:none on the select.
Webkit outputs -1 while FF, IE, Opera output 0.

Removal of the display:none gives consistent behavior among all browsers.
So it seems the display style is affecting the selects initial selectedIndex.

Also, when the display is none, and selectedIndex is accessed prior to making multiple = true, then it works fine.
Comment 1 Emil A Eklund 2011-03-03 15:35:29 PST
Created attachment 84640 [details]

This patch changes the behavior of <select> elements with display: none to match the behavior of elements that are displayed.
Comment 2 Dimitri Glazkov (Google) 2011-03-08 13:58:17 PST
Comment on attachment 84640 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=84640&action=review

engage the tractor beam.

> Source/WebCore/ChangeLog:5
> +        style.display affecting the initial selectedIndex value of a <select> when it's multiple attribute is set programatically

it's -> its

> Source/WebCore/html/HTMLSelectElement.cpp:437
> +    int oldSelectedIndex = selectedIndex();

Can you add a comment on why we're doing this here? Out of context, the reasoning behind this line is hard to guess.
Comment 3 Emil A Eklund 2011-03-08 14:15:22 PST
Created attachment 85089 [details]

Made suggested changes, PTAL.
Comment 4 Dimitri Glazkov (Google) 2011-03-10 11:47:40 PST
Comment on attachment 85089 [details]

Comment 5 WebKit Commit Bot 2011-03-10 20:23:13 PST
Comment on attachment 85089 [details]

Clearing flags on attachment: 85089

Committed r80808: <http://trac.webkit.org/changeset/80808>