Closed Bug 425271 Opened 16 years ago Closed 16 years ago

listitem elements that use the type='checkbox' attribute are only set to true if they are visible in the listbox

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 250123

People

(Reporter: linuxed7, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b5pre) Gecko/2008032505 Minefield/3.0b5pre
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b5pre) Gecko/2008032505 Minefield/3.0b5pre

This bug appears to be present in all version of Gecko 1.9.  I've verified it
in Firefox 3, SeaMonkey 2, Songbird 0.4/0.6.  It does not occur in Gecko 1.8.1.

Basically any listitem that appears in a listbox with the type='checked' attribute will only return listitem.checked==true if it is visible in the listbox.  So if you have a listbox with 5 visible rows, but you have 10 listitems in that box, then only 5 of the listitems' checked attributes will return true even if they're all checked.

Reproducible: Always

Steps to Reproduce:
1. Create a listbox and set the rows attribute to something like 5.
  <listbox seltype="single" rows="5" flex="1"/>
2. Then using javascript add listitem elements to the listbox totaling more
than the visible number of rows.  Let's say 10 listitems.  Make sure to set
each checked attribute to true.
  for (var i=0; i<10; ++i) {
    listitem = document.createElement('listitem');
    listitem.setAttribute('type','checkbox');
    listitem.setAttribute('autocheck','true');
    listitem.setAttribute('checked','true');
    listitem.setAttribute('label','thisIsATest');
    listbox.appendChild(listitem);
  }
3. Using javascript grab all of the listitem elements and test the length of
the array.
  var listitems = document.getElementsByTagName('listitem');
  alert(listitems.length);
4. Then loop through the listitems, save the elements which have their checked
attribute set to true, and alert the number of checked elements.
  var test = [];
  for (var i=0; i<listitems.length; ++i) {
    if (listitems[i].checked) test.push(listitems[i]);
  }
  alert(test.length);

Actual Results:  
Using getElementsByTagName() correctly grabs all 10 listitems.  However when
looping through them and testing the checked attribute only the visible items
will return true.  So when you alert the test.length it only shows that 5 are
checked because the other 5 are not visible in the listbox.


Expected Results:  
Every checked listitem element should return true when you're looping through
them, regardless of whether they are visible in the listbox.


I created a test version of the CS Lite extension which you can download from
the link below.  To view this bug first install the test version in Firefox. 
Then right click on the cs lite icon and click the 'Update Blocklist'
menuitem.  Click 'Block' when the popup window appears.  You will be shown 3
alert boxes.  The first is the getElementsByTagName() array length.  The second
is the listbox row count (box.getRowCount()).  The third is the number of items
that are checked.  It displays 8 in the alert since only 8 are visible, however
there are a total of 251 elements that are checked.  This problem does not seem
to appear in Gecko 1.8.1 (FF2).  I've also noticed that if you scroll to the
bottom of the listbox it will successfully detect all of the checked elements. 
It's only if you click 'Block' before scrolling down that all of the checked
elements are not successfully detected.

http://forum.softwareblaze.com/cslite/cslite-test.xpi
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.