Open Bug 531537 Opened 15 years ago Updated 2 years ago

menulist.removeAllItems destroys menulist.menupopup instead of removing all items, breaks onmenupopup handler of menulist

Categories

(Core :: XUL, defect)

defect

Tracking

()

People

(Reporter: thomas8, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

2.31 KB, application/vnd.mozilla.xul+xml
Details
Attached file Interactive Test case
OK folks, here's my first bug against XUL...
(thanks to Ben Bucksch who gently pushed me into examining this, although I'm really still learning XUL... ;)

menulist.removeAllItems destroys the entire <menupopup> child of the menulist, where it should really only "remove all items" _within_ that menupopup (the children of menupopup). Not only are we destroying all attributes of the original <menupopup...> tag (like id etc.), but also this actually breaks the menulist's onpopupshowing handler, if you call menulist.removeAllItems and then re-append items from within the handler (with the intent of updating/recreating the list of menuitems before it pops up). So the popup doesn't show up :(

This is the bad code:

function removeAllItems() {
  this.selectedItem = null;
  var popup = this.menupopup;
  if (popup) {
    this.removeChild(popup) // this is too destructive and breaks the popup
  }
} 

And this should fix it (I hope):

function removeAllItems() {
  this.selectedItem = null;
  var itemCount = this.itemCount;
  for( var i = (itemCount-1); i >= 0; i-- ) this.removeItemAt(i);
} 

Other people have seen this bug as well:
http://bugs.code.downthemall.net/trac/changeset/1555 (line 404 :)))
Thanks a lot, Thomas, for filing the bug and the minimal testcase!

I hope somebody will pick it up?
Moving to Core:XUL per https://bugzilla.mozilla.org/show_bug.cgi?id=1455336
Component: XP Toolkit/Widgets: XUL → XUL
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: