problem
When adding a "click" event to a Ti.UI.Button in Mobileweb, the event object's "source" property is not the Ti.UI.Button that a developer would expect. Instead a Ti.UI.View seems to be returned that does not actually represent the button. My first thought was that it had something to do with event bubbling, but only one occurrence of the event is fired and it only returns this somewhat bogus object. Just to be sure I set e.cancelBubble to true and I still encounter the same issue.
The use of e.source for identification is fairly common when multiple UI components will be referencing the same callback function. Android and iOS behave as expected, returning the Ti.UI.Button as the
e.source
.
test case
The issue surfaced in one of the Alloy test apps, but I've reduced it to a minimal, traditional Titanium test case.
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var button = Ti.UI.createButton({
title: 'press me'
});
button.addEventListener('click', function(e) {
alert('source: ' + e.source.title + '\nobject: ' + e.source.toString());
});
win.add(button);
win.open();
Essentially, I would expect that the output of clicking the button would be:
source: 'press me'
object: [object TiUIButton]
where I could then make decisions in my callback based on the title property of the button. Instead, it returns this which is not in line with the other platforms:
source: undefined
object: [object TiUIView]
Also I am not relying solely on the text output. I've tested the returned object and it is not a Button that happens to be returning the wrong information.
expected
e.source
in the above test case should return a reference to the Ti.UI.Button that was clicked.
Marking ticket as "Won't Fix" as MobileWeb has been deprecated.
Closing as will not fix.