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
RapsFan
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
Accepted Solution

Can't get toast to show

I'm succesfullt making a $.ajax call and can even get a javascript alert to show that it was successful but when I try and use a toast nothing happens. I added the toast plugin and see it in the plugin directory, I also added <feature id="blackberry.ui.toast" /> in my config.xml.

Below is my javascript&colon;

App.init = function () {
App.utils.metaHack();
$(document).ready(function() {
$("#regsubmit").click(function(){

var formData = $("#adduser").serialize();
alert(formData); 
$.ajax({
type: "POST",
url: "http://www.hedonsoft.com/tcob/php/register.php",
cache: false,
dataType:"text",
data&colon; formData,
success: showCustomToast
});
return false;
}); 
});
$('#landing').live("pagecreate", function(){
navigator.geolocation.getCurrentPosition(App.getLocation);
});
$("#bb_activity").live("pageinit", function(){
App.page.bb_activity.init();
}); 
$("#togglePage, #togglePageDark").live("pageinit", function(){
App.page.toggle.init();
});
$("#actionBarSample").live("pageinit", function() {
App.page.actionBarSample.init();
});
$('#applicationMenu').live("pageinit", function() {
App.page.applicationMenu.init();
});
}
function showCustomToast(data, status) {
if(data=="SUCCESS"){
var message = 'This is a simple Toast';
blackberry.ui.toast.show(message);
}
}

 

What am I missing?

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

Re: Can't get toast to show

Can you please confirm that you are waiting for the 'webworksready' event to fire before you try to invoke any blackberry APIs?

Have you connected Web Inspector to your application to see if any errors are occurring in the Console log? This would likely be the best starting point to help identify any issues.

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.
Developer
RapsFan
Posts: 442
Registered: ‎08-02-2010
My Device: Z10

Re: Can't get toast to show

I was following the code on https://github.com/blackberry/BB10-WebWorks-Samples/tree/WebWorks-2.0/Toast and didn't see a 'webworksready' event. How is my code different from theirs! (I'm not using bbui btw, jQuery Mobile with bb10 theme)
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: Can't get toast to show

[ Edited ]

Ah, correct if you are using the Cordova-based WebWorks 2.0 SDK, then there is no webworksready event, instead you wait for deviceready as outlined in the sample's index.html.

https://github.com/blackberry/BB10-WebWorks-Samples/blob/WebWorks-2.0/Toast/www/index.html

 

The code you are using looks fine; I would place a console.log('Here') after the call to blackberry.ui.toast, then create a debug version of the application, connect Web Inspector, and verify that:

1) The console doesn't list any errors when the toast message is being displayed / should be displayed.

2) Your custom message Here shows up in the Console log of Web Inspector.

 

EDIT: As you are using the Cordova-based SDK, did you include the toast plugin through this command?

webworks plugin add com.blackberry.ui.toast

 


Docs: https://developer.blackberry.com/html5/apis/beta/blackberry.ui.toast.html


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.
Developer
RapsFan
Posts: 442
Registered: ‎08-02-2010
My Device: Z10

Re: Can't get toast to show

Yes I did include the plug in. Will try the Web inspector and let you know what I come up with.
Please use plain text.
Developer
RapsFan
Posts: 442
Registered: ‎08-02-2010
My Device: Z10

Re: Can't get toast to show

Ok the errors I'm getting in the web inspector console are

 

Can't find variable cordova

and

Can't find variable BlackBerry.

 

Did I forget to include something?

Please use plain text.
Developer
RapsFan
Posts: 442
Registered: ‎08-02-2010
My Device: Z10

Re: Can't get toast to show

Including these fixed the problem.

 

<script src="local:///chrome/webworks.js"></script>
<script type="text/javascript" src="cordova.js"></script>

Please use plain text.