If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Can a bbui first screen have attached js?

So my first page (index.html) has code:

 

<html>
<head>
<meta name="x-blackberry-defaultHoverEffect" content="false" />
<meta name="viewport" content="initial-scale=1.0,width=device-width,user-scalable=no,target-densitydpi=device-dpi" />
<link  rel="stylesheet" type="text/css" href="bbui-0.9.4.css" />
<link rel="stylesheet" href="leaflet.css" />
<script type="text/javascript" src="leaflet.js"></script>
<script type="text/javascript" src="bbui-0.9.4.js"></script>
<script type="text/javascript">

var fs_id = '';
var sp_id = '';
var rv_id = '';
var use_i = '';
var gps_c;

bb.init({
	bb10ActionBarDark: true,
	bb10ControlsDark: true,
	bb10ForPlayBook: true,
	ondomready: function (element, id) {
	if (id == "profile") {
		doRecallProfile();
    } else if (id == "reporttime") {
		reporttime_addListItem();
	} else if (id == "studydetails") {
		studydetails_addListItem();
	} else if (id == "showreturns") {
		returndetails_addListItem();
	} else if (id == "edittime") {
		edittime_updateInputs();
	} else if (id == "editinterest") {
		editinterest_updateInputs();
	} else if (id == "editstudy") {
		editstudy_updateInputs();
	} else if (id == 'map_screen') {
		create_map();
	}
  }
});

</script>
</head>
<body onLoad="bb.pushScreen('menu.html', 'dashboard');">
</body>
</html>

My question is:  Can the first page -> menu.html have an attached javascript file that gets run much like the profile and other pages I have here?

 

I tried placing an id here for 'dashboard' but it comes up blank and I get "Cannot set property 'innerHTML' of null" errors meaning that the DOM is not ready or loaded.

 

suggestions?

 

If it helped you, click like. :smileyhappy:
Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 614
Registered: ‎10-01-2009
My Device: Z10
My Carrier: Bell

Re: Can a bbui first screen have attached js?

Hello,

 

You can include inline scripts like this:

 

<div data-bb-type="screen" data-bb-effect="slide-left">
	<script id="actionBarJS" src="js/actionBar.js"></script>

<script>
console.log('this is an inline script');
</script>
</div>

 

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: Can a bbui first screen have attached js?

Tried that, didn't work.

 

Also I just read today on the bbui.js wiki that you cannot include inline js when using pushscreen, so your suggestion although a good one has no effect.  Unless I did it wrong of course.  I think the wiki info still stands though.

If it helped you, click like. :smileyhappy:
Please use plain text.
Developer
Developer
LBP
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: Can a bbui first screen have attached js?

To use inline JS when using bbUI.js I recommend to use the onscreenready and/or ondomready events for such things. With this you are able to call "inline" JS if neccessary when the screen was added. Have a closer look to the Toolkit Initialization wiki page for more informations.

 

And there is also the wiki page about Screen Specific CSS and JavaScript that attributes things that might be interesting for you. The page covers how to add CSS and JS by source and also as inline elements directly.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Please use plain text.
BlackBerry Development Advisor
chadtatro
Posts: 614
Registered: ‎10-01-2009
My Device: Z10
My Carrier: Bell

Re: Can a bbui first screen have attached js?

Hi there,  did LBP's suggestion work for you?  

 

If so could you please mark it as an accepted solution?  If not, let us know :smileyhappy:

Chad Tetreault | App Development Consultant | BlackBerry Developer Relations | developer.blackberry.com | @chadtatro
Please use plain text.
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: Can a bbui first screen have attached js?

Sorry haven't been able to get back to my app to try that suggestion.  Will try it over the next few days.  Tx for the feedback.

If it helped you, click like. :smileyhappy:
Please use plain text.