Open Bug 350309 Opened 18 years ago Updated 2 years ago

JS exception when you use addItemToSelection when there are no rows selected

Categories

(Toolkit :: UI Widgets, defect)

1.8 Branch
defect

Tracking

()

People

(Reporter: db48x, Unassigned)

Details

Assigning the row to the selectedItem property does work, however.

* Call to xpconnect wrapped JSObject produced this error:  *
[Exception... "'[JavaScript Error: "this.selectedItems has no properties" {file: "chrome://global/content/bindings/listbox.xml" line: 264}]' when calling method: [nsIController::doCommand]"  nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)"  location: "JS frame :: chrome://global/content/globalOverlay.js :: goDoCommand :: line 93"  data: yes]
fwiw, here's the code I'm using. If you take out the line before the call to addItemToSelection you'll see the exception.

function manipulateSelectedAboutItems(action)
{
  var list = document.getElementById('list');
  var rows = list.selectedItems;

  rows = rows.map(function(elem) { return elem; });
  rows = rows.map(action, list);

  rows[0] && (list.selectedItem = rows[0]);
  rows.forEach(list.addItemToSelection);

  var nodes = list.childNodes;
  var len = nodes.length;

  gItems = [];
  for (var i = 0; i < len; i++)
    if (nodes[i].nodeName == 'listitem')
      gItems.push(nodes[i].childNodes[1].getAttribute('label'));

  return rows;
}
This needs a proper testcase
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.