Aeonstrife
Aeonstrife

Reputation: 673

Buttons in a listcell XUL

Is there a way to get buttons in a listcell to work in XUL? I'm not sure what is stopping it from running. The XUL looks like :

<listitem id = "1">
    <listcell label = "OK Computer"/>
    <listcell label = "Radiohead"/>
    <listcell label = "1997"/>
    <listcell label = "Platinum"/>
    <listcell label = "5/5"/>
    <listcell label = "Alternative Rock"/>  
    <button label = "Edit" oncommand= "alert('Hello World');"/>
    <button label = "Delete" oncommand = "deleteItem();"/>  
</listitem>

The button works fine outside of the list but my mouse pointer doesn't even recognize it as a button (by changing to a hand pointer) when it's in the list. Any ideas?

Upvotes: 0

Views: 142

Answers (2)

Philipp Kewisch
Philipp Kewisch

Reputation: 992

Buttons and other control elements can be used in a standard listitem, it is not required to use richlistbox or tree. The magic trick is the allowevents attribute. You might also want to wrap the buttons in a listcell itself so they get their own column.

<listitem id="1" allowevents="true">
    <listcell label="OK Computer"/>
    <listcell label="Radiohead"/>
    <listcell label="1997"/>
    <listcell label="Platinum"/>
    <listcell label="5/5"/>
    <listcell label="Alternative Rock"/>  
    <listcell>
        <button label="Edit" oncommand="alert('Hello World');"/>
        <button label="Delete" oncommand="deleteItem();"/>  
    </listcell>
</listitem>

Upvotes: 1

Wladimir Palant
Wladimir Palant

Reputation: 57651

You need to put the buttons inside the list cell:

<listcell>
  <button label="Edit" oncommand="alert('Hello World');"/>
</listcell>

A list cell can either have the default contents (which is what you get if you simply add a label attribute and no contents) or anything you want - but for the latter you actually have to put the contents into the <listcell> tag explicitly.

Edit: Actually, the more important problem is that <listbox> is rather restricted concerning its contents, it is mostly limited to plain text. Which is why the more generic <richlistbox> widget has been developed. It doesn't support tabular content however.

Upvotes: 0

Related Questions