blackberry / bbUI.js

BlackBerry UI look and feel JavaScript toolkit for WebWorks
Apache License 2.0
312 stars 192 forks source link

onclick function passing Window for 'this' instead of actual DOM object #1005

Closed rsf38 closed 10 years ago

rsf38 commented 10 years ago

I have an image list with items that have an onclick attribute on them of "callFn(this)";

I have an app using WebWorks BBOS 1.0 and BBUI 0.9.4 in which this code will properly send the item in the list as the parameter to the function.

I am now converting to BB10 with Webworks BB10 1.0 and BBUI 0.9.6. With the same code, I am receiving the Window object inside of callFn instead of the item object. [Edit: I'm just using Ripple right now, not quite at point to package it for simulator yet.]

Any reference to this in the onclick attribute (i.e. this.id) ends up referring to the Window, so it has become useless. The workaround I'm using is to use setAttribute("onclick"...) and pass the id of the item instead of using this, but using "this" is so much easier.

rsf38 commented 10 years ago

Nevermind. I found the selected property which works as well, if more verbose. But I assume was done to be consistent with context menus. Will action bars get the same selected property for use in action onclick?

tneil commented 10 years ago

I believe for action you will need to assign a separate function for the event handler. I assume you are trying to have a single function for multiple actions and the this value isn't evaluating the way you expect?

raakhtar commented 10 years ago

Hello Tim,

Thanks for quick reply. I am using WebWorks 1.0 and when I use old version of BBUI js, I am not getting duplicate behaviour but I donot want to use old BBUI as context menu appears to be faster in the latest version of BBUI.

Moreover, using Webworks 2.0 with BBUI is giving blank screen randomly when back button is pressed from action bar from inner pages.

rsf38 commented 10 years ago

Thanks Tim, that was the issue. I had a single handler and passed this in order to know which item in the list was pressed. In Webworks BB10 1.0 and bbui 0.9.6, I had to change the handler to use document.getElementById( 'myList' ).selected to get the item that was pressed. Works well now.