e.source what type of ?

You must Login before you can answer or comment on any questions.

Hey,

i have a tableviewrow and on it there is a Button.

Now i wanna do 2 different functions, if the user presses the row or the button instead.

eventTableView.addEventListener('click', function(e) {
                /*Ti.App.fireEvent('app:event.select', {
                    name:e.rowData.title
                });
                */
                var target = e.source;
                Ti.API.info(e.source);
                switch(target)
                {
                    case TiUIButton:
                    Ti.API.info("Button");
                    break;
 
                    default:
                    Ti.API.info("Row");
                    break;
                }
            });
I've tried several things but nothing works... any idea?

2 Answers

Hello ,

Try this approach may this works for you :

You can, in table view event listener, check if event source is a button:

tableView.addEventListener('click', function(e) {
 
 var buttonString = e.source.toString();
if(buttonString == '[object TiUIButton]' || buttonString == '[Ti.UI.Button]') {
    // do work for button click
} 
else
{
//do work for row click
 
}
 
});

— answered 10 months ago by Moiz Chhatriwala
answer permalink
2 Comments
  • If you also want to detect which row number has got clicked that you can check through

    e.index
    Another option is Using custom property solves this problem

    While creating button you can create custom property

    var button = Titanium.UI.createButton({
       title: 'Dont use toString :D'
    });
    button.isButton = true;
     
    //in table view "click" event handler
    if(e.source.isButton) {
        return;
    } 
    else{
    // table view row clicked
     
    }

    — commented 10 months ago by Moiz Chhatriwala

  • Did this help you , please do mark as accepted , if this solves your problem.

    — commented 10 months ago by Moiz Chhatriwala

you can also just assign ids to the objects like you do in HTML and check the id of the source object

var button = Titanium.UI.createButton({
   title: 'Dont use toString :D',
   id : "row_button"
});
 
 
eventTableView.addEventListener('click', function(e) {
    if (e.source.id === "row_button") {
    }
})

Your Answer

Think you can help? Login to answer this question!