All users were logged out of Bugzilla on October 13th, 2018

Listbox (select) does not scroll to selected line

RESOLVED WORKSFORME

Status

()

RESOLVED WORKSFORME
15 years ago
4 years ago

People

(Reporter: matthias_rgaw, Unassigned)

Tracking

({testcase})

Trunk
x86
All
testcase
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Reporter)

Description

15 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007

If a listbox (select) is placed within a table where the cell (<td>) has the
attribute align="center", the listbox does not initially show the selected line.

html code to reproduce behavior:

<html>
<head><title>Listbox Problem</title>
</head>
<body><form><table>
<tr>
<td align="center">
<select id="day" name="day" tabindex="1" size="7">
<option value="20.09.2003">Sa 20.09.2003</option>
<option value="21.09.2003">So 21.09.2003</option>
<option value="22.09.2003">Mo 22.09.2003</option>
<option value="23.09.2003">Di 23.09.2003</option>
<option value="24.09.2003">Mi 24.09.2003</option>
<option value="25.09.2003">Do 25.09.2003</option>
<option value="26.09.2003">Fr 26.09.2003</option>
<option value="27.09.2003">Sa 27.09.2003</option>

<option value="28.09.2003">So 28.09.2003</option>
<option value="29.09.2003">Mo 29.09.2003</option>
<option value="30.09.2003">Di 30.09.2003</option>
<option value="01.10.2003">Mi 01.10.2003</option>
<option value="02.10.2003">Do 02.10.2003</option>
<option value="03.10.2003" selected >Fr 03.10.2003</option>
<option value="04.10.2003">Sa 04.10.2003</option>
<option value="05.10.2003">So 05.10.2003</option>
<option value="06.10.2003">Mo 06.10.2003</option>
</select>
</table></form></body>
</html>

Reproducible: Always

Steps to Reproduce:
1. Save above code into a html document
2. open this document


Actual Results:  
listbox shows first line

Expected Results:  
listbox should scroll to the selected line
Why do we ever scroll to the <option selected>?  That seems like odd behavior to
me...
(Reporter)

Comment 2

15 years ago
are you serious?
%) matthias
Yes, I am.  Perhaps I should clarify the question... "I just looked through the
listbox code, and I fail to see what would trigger this scrolling.  What code
actually triggers it?"

Comment 4

15 years ago
Adding me to the CC list.

I have just noticed this bug when testing a PHP script. I have found out that IE
behaviour is exactly the requested on this bug: if an item is selected by
default, the select element should be scrolled to allow seeing the item
selected. I suggest to change the status to NEW.

Oh, and it is important to keep in mind that the attribute "align=center" in the
TD tag is not necessary for reproducing the bug.

Comment 5

15 years ago
I have made a little JavaScript function as a workaround for this bug. It's
quite simple and more or less secure:

function ScrollSelect(sel){
  //function used as workaround of Mozilla bug:
  // http://bugzilla.mozilla.org/show_bug.cgi?id=224023

  if ((sel.options.length>1)&&(sel.selectedIndex!=-1)){
    sel.focus();

    i = sel.selectedIndex;

    if (sel.options.length-1!=i) 
      //not the last option selected
      sel.selectedIndex=sel.options.length-1;
    else
      sel.selectedIndex=i-1;

    sel.selectedIndex=i;
  }
}

This function could be called by the page using something like (supposing
"form1" as the name of the form, and "sel1" the name of the select input control):

<body onLoad="ScrollSelect(window.document.form1.sel1);">

Although this workaround won't be useful when JavaScript is disabled for the
browser. This is the reason for me to think that we need this bug to be resolved
for Mozilla (at least, it should be marked as NEW).

Regards.

Comment 6

15 years ago
I had a mistake in my comment #4. The align="center" is a requisite for the
reproduction of the bug.

The best way to notice the bug is displaying the HTML example that gave
Matthias. If the attribute align="center" is removed, Mozilla scrolls the SELECT
(BTW, I am answering to Boris, I think).
confirmed with trunk build 20040111908
I can't see why a list should behave differently with and without align="center"
on the cell, it's not consistent.
Status: UNCONFIRMED → NEW
Ever confirmed: true

Comment 8

15 years ago
I have found a very representative URL in bugzilla for this bug:

http://bugzilla.mozilla.org/enter_bug.cgi?format=__default__&product=mozilla.org&component=webmaster@mozilla.org&version=other&rep_platform=All&op_sys=All&bug_file_loc=http://www.mozilla.org/hacking/portable-cpp.html&short_desc=%3CSummarize+your+changes+here.%3E&comment=%3CDescribe+your+changes+here+in+more+detail.++After+you+commit+this+bug+report%2C%0D%0Aclick+the+%22Create+Attachment%22+link+to+add+the+changes+to+the+report+as+an%0D%0Aattachment.%3E
(Perhaps it is useful to have this URL on the URL field for the bug, but I have
not enough permissions to change it.)

As you see, when you display that page, the SELECT control which allows
selecting the Component, has a selected value, but the Select is not properly
scrolled (if you scroll the SELECT manually, you can see the selected item).

I also have made an optimization for the workaround in JavaScript that I noticed:

function ScrollSelect(sel){
  //function used as workaround for Mozilla bug:
  // http://bugzilla.mozilla.org/show_bug.cgi?id=224023

  if ((sel.options.length>1)&&(sel.selectedIndex>0)){
    sel.selectedIndex--;
    sel.selectedIndex++;
  }
}

Comment 9

14 years ago
Created attachment 153737 [details]
Testcase
Bug still occurs, 2004-07-18-05 trunk Linux.  The regression occured somewhere
between Mozilla 1.3 and 1.4 releases.
Severity: minor → normal
Keywords: testcase
OS: Windows XP → All

Comment 11

14 years ago
Created attachment 154028 [details]
Demonstration of Scrolling Bug When 'disabled' is set and unset.

Using javascript to scroll a listbox by setting selectedIndex to a position
fails when disabled is set to 'true' and then back to 'false'.	This attachment
demonstrates this bug.

Updated

14 years ago
Attachment #154028 - Attachment mime type: application/octet-stream → video/mpeg

Comment 12

12 years ago
However this can be made to work by a work-around by replacing the innerHTML of the select statement as follows -
<select>
<option value="Page1">
<option value="Page2">
<option value="Page3">
<option value="Page4"> 
<select>

If option 3 needs to be as selected then using innerHTML replace the option 3 html text as:
<option value="Page3" selected="selected">

So it now looks like -

<select>
<option value="Page1">
<option value="Page2">
<option value="Page3" selected="selected">
<option value="Page4"> 
<select>

This way I am able to set the option as selected.
Assignee: layout.form-controls → nobody
QA Contact: ian → layout.form-controls
Works for me, both when loading the test attachment directly from Bugzilla and from
a local saved file.  Nightly 37.0a1 (2015-01-01) on Linux64.
Can anyone else reproduce the problem?
Flags: needinfo?(matthias_rgaw)
Whiteboard: [closeme 2015-01-26]

Comment 14

4 years ago
Resolved per whiteboard and Comment 13
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Flags: needinfo?(matthias_rgaw)
Resolution: --- → WORKSFORME
Whiteboard: [closeme 2015-01-26]
You need to log in before you can comment on or make changes to this bug.