DerZyklop
DerZyklop

Reputation: 3813

Event "press" on sap.m.CustomListItem doesn't work

The dokumentation of sap.m.CustomListItem says that CustomListItem hat a press event.

I created a site with the press event on a list item, and another press event on a Button inside the list item. The button works fine. A click on the list item shows nothing. Not even an error.

var oCustomItem = new sap.m.CustomListItem({
    content: [
        new sap.m.Text({
            text: "{text}"}),
        new sap.m.Button({
            text: "btn",
            press: function(){
              alert("Pressed the button");
            }
        })
    ],
    press: function(){
      alert("Clicked the list item");
    }
});

Here is an example: http://jsbin.com/pozeve/4/edit?html,output

Upvotes: 2

Views: 6393

Answers (1)

Tim Gerlach
Tim Gerlach

Reputation: 3390

This is a frequent issue people face when they´re using List controls. There´s an answer to this here.

To put it in a nutshell, you either have to add a type property to your CustomListItem:

var oCustomItem = new sap.m.CustomListItem({
    content: [
        new sap.m.Text({
                text: "{text}"}),
            new sap.m.Button({
                text: "btn",
                press: function(){
                    alert("Pressed the button");
                   }
                })
            ],
            type : sap.m.ListType.Active,
            press: function(){
              alert("Clicked the list item");
            }
});

or a mode property to your sap.m.List. For a comparison see the answer mentioned above.

Upvotes: 4

Related Questions