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
Trusted Contributor
Magnetic_dud
Posts: 116
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

BBui.js - how to programmatically push a screen?

Well, I tried to do this in my function

 

$(document).ready(function() {
    console.log("ima ready");
    bb.pushScreen('results.htm', 'results');
});

 

It doesn't work, I get Uncaught ReferenceError: element is not defined

 

How to do that?

Please use plain text.
Developer
bnolan001
Posts: 127
Registered: ‎02-19-2011
My Device: Bold 9930 and PlayBook

Re: BBui.js - how to programmatically push a screen?

Does it say that bb is not defined?

"Not to know what happened before you were born is to be forever a child." Marcus Tullius Cicero
Please use plain text.
Trusted Contributor
Magnetic_dud
Posts: 116
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: BBui.js - how to programmatically push a screen?

I am not sure, I just see that in Ripple console...

 

I call it from an external function.

 

I do like this

 

The main menu loads a "please wait" page, the I do my data loading (around 3 seconds), and then I want to call the results page.

Please use plain text.
Developer
26filip
Posts: 225
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: BBui.js - how to programmatically push a screen?

Stupid question: do You have included jQuery script? 

It's look like Ripple or Web Browser don't recognize "$"

All time online :smileyvery-happy:
Please use plain text.
Trusted Contributor
Magnetic_dud
Posts: 116
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: BBui.js - how to programmatically push a screen?

Yes jquery is loaded from the first page

Maybe I did it wrong?

Later I will check

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: BBui.js - how to programmatically push a screen?

Hi there, within Web Inspector, have you placed a break-point in your code and stepped through to see exactly which line of code is throwing the error? Perhaps it is something inside of BBUI.js?

For instance, perhaps WebWorks hasn't completely initialized yet (are you waiting on the webworksready event?) and BBUI is failing. Or perhaps the HTML file reference (admittedly less likely) is incorrect if the file is in a separate folder?

The error itself is pretty generic, so if you could step through / into and provide the exact line of code that generates the error, that would help narrow down the cause.

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.
Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 614
Registered: ‎10-01-2009
My Device: Z10
My Carrier: Bell

Re: BBui.js - how to programmatically push a screen?

Also, are you initializing bbUI.js before trying to push?

 

try following this example: https://github.com/blackberry/bbUI.js/wiki/Toolkit-Initialization

 

<html>
      <head>
          <link  rel="stylesheet" type="text/css" href="bbui-0.9.4.css"></link>
          <script type="text/javascript" src="bbui-0.9.4.js"></script>
          <script type="text/javascript" src="js/webworks-1.0.2.9.js"></script>
          <script type="text/javascript">
          document.addEventListener('webworksready', function(e) {
              bb.init();
              // Open our first screen
              bb.pushScreen('firstScreen.htm', 'firstScreen');
          }, false);
          </script>
      </head>
      <body>
      </body>
  </html>

 

 

 

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.
Trusted Contributor
Magnetic_dud
Posts: 116
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: BBui.js - how to programmatically push a screen?

But it's already initialized

I initialize again?

Please use plain text.
Trusted Contributor
Magnetic_dud
Posts: 116
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: BBui.js - how to programmatically push a screen?

I explain better what I do

 

index.htm initializes bbui.js and loads the page with

 

bb.pushScreen('load.htm', 'load');

 

load.htm is loaded and displayed

 

at the end of the screen div there is this js:

 

<script type="text/javascript">
console.log("i will run my function");
myfunction('address');
console.log("i ran my function");
</script>

 

As expected, console displays both lines.

 

myfunction is loaded

 

function myfunction(address)
{
console.log("myfunction start!");
localStorage.setItem.... (my stuff)
...
console.log("i try to push the page");
bb.pushScreen('results.htm', 'results');
console.log("pushed");

}

 

I get all the console lines except pushed, and the page is not pushed. 

I guess because I am pushing the screen in the wrong way

Please use plain text.
Developer
26filip
Posts: 225
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: BBui.js - how to programmatically push a screen?

The better way is including JS from files, instead in HTML source.

By me JS in HTML source not work - only that in JS file.
All time online :smileyvery-happy:
Please use plain text.