Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Posts: 15
Registered: ‎11-23-2013
My Device: BB Z10
My Carrier: Idea

addEventListener Not Working in Phone working good in Emulator

Hi, I am really new to javascript and blackberry.

 

I am using bbui for pusing and pop div in html page , quiet simple.But not using all its UI. Only screen.

 

When i am trying to add eventlistner on my button , using javascript .I am getting no result in phone but working fine in

emulator.

 

My Code is like this .

 

window.addEventListener('load',function() {
document.addEventListener('webworksready', function(e) {
bb.init({
onscreenready: function (element, id) {

if (id == "loginscreen") {
loadjscssfile("javascript/login.js","js");

}}, false);

}, false);

 

 

and then in login.js file i wrote some thing like this .

 

var signUp = document.getElementById('submitbutton');
signUp.addEventListener('click',login,false);

 

 

It is working fine in emulator but not working in phone bbz10.

Also  Is bbui is use full to use for only push and pop , or i can use something else as i do not want default bb style i am lokking for the idea of push and pop only ?

 

 

 

BlackBerry Development Advisor
Posts: 762
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: addEventListener Not Working in Phone working good in Emulator

Hello,

 

Have you tried adding a "onclick" to the html of the button instead of setting an eventListener? Because of the way bbUI populates the DOM, you may need to use this approach instead.

 

Something like: <button id="submitButton" onlick="login();"> this is a button </button>

 

From my experience, bbUI is the best framework to use at the moment. Even though you're only using it for the screen pushing/popping, it's still faster than the other alternatives out there in my opinion. I would stick with it.

 

 

New Developer
Posts: 15
Registered: ‎11-23-2013
My Device: BB Z10
My Carrier: Idea

Re: addEventListener Not Working in Phone working good in Emulator

Hi ,

Thanks chadtatro. Actually using evenlistner like this is not advice, Actually when i am trying to click the button multiple times , multiple screen get pushed . Any way to solve this . as i can not do event.preventdefault(); .

 

 

 

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: addEventListener Not Working in Phone working good in Emulator

I'm not quite sure I follow:
" when i am trying to click the button multiple times , multiple screen get pushed"

Would that not be the expected behaviour for a button being pushed multiple times? (Specifically firing multiple times?)


Also, I'm a bit wary of the usage of: loadjscssfile

Specifically re-loading the JS and CSS via onscreenready *every time*. BBUI has a built-in way to load custom CSS and JS:
https://github.com/blackberry/bbUI.js/wiki/Screen-Specific-CSS-and-JavaScript


As an alternative:

Instead of onscreenready, could you try adding the event listener code to the ondomready?

Also, onromready contains an "element" parameter. Instead of calling document.getElementById, could you leverage element.getElementById instead?

This will allow you to more efficiently get the DOM element associated with the screen, after the DOM manipulation has already happened, minimizing the potential for issues.

Please let me know if you have any questions.

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
New Developer
Posts: 15
Registered: ‎11-23-2013
My Device: BB Z10
My Carrier: Idea

Re: addEventListener Not Working in Phone working good in Emulator

I did not get it exactly, I think the element parameter is in both onScreenReady and onDomReady. OK i will try adding listeners in onDomReady ,

Thank you
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: addEventListener Not Working in Phone working good in Emulator

[ Edited ]

Correct, element is present in both and, in each, represents the actual screen from your HTML fragment.

The main difference is that onscreenready fires before BBUI has done all of its magic to manipulate the screen element.

ondomready fires after all of that is done (i.e. the screen DOM is ready.) In that case, element represents the screen, and you can use those APIs to access objects on the screen (i.e. element.getElementById).

 

UPDATE


I just wanted to check in, did adding the listeners during ondomready via the element variable (as opposed to document) give any better results? The key thing is that the screen may not have been added to the actual document yet, meaning we want to access it directly (via element) and after the DOM is ready so that BBUI isn't replacing any of our efforts.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.