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

Toast button callback not firing

When I click my Toast's button nothing is happening. I'm using the Web Inspector and not getting any response in the console.

 

.ajax({
            type: "POST",
            url: "localhost://register.php",
            cache: false,
            dataType:"text",
            data: formData,
            success: function(data, status){

        var jsonData = JSON.parse(data);
            showToast();
            }
...

function showToast()
{
var message = "This is my toast!",
            buttonText = "Click Me",
            toastId,
            onButtonSelected = function () {
                console.log('Button was clicked for toast: ' + toastId);
            },
            onToastDismissed = function () {
                console.log('Toast disappeared: ' + toastId);
            },
            options = {
                buttonText : buttonText,
                dismissCallback : onToastDismissed,
                buttonCallback : onButtonSelected
        };

        toastId = blackberry.ui.toast.show(message, options);
    }

 

 

BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: Toast button callback not firing

Which SDK are you using to build the application? Note that Toast won't work in the browser.

I'll see if I can reproduce this issue on my end, but will need to match the same SDK approach you're using.

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

Re: Toast button callback not firing

I'm testing on a device with the newest sdk
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: Toast button callback not firing

[ Edited ]

I just gave it a try with the following steps. From the Command Line (CLI) I executed the following:

 

C:\webworks>webworks create toast

C:\webworks>cd toast

C:\webworks\toast>webworks plugin add com.blackberry.ui.toast

C:\webworks\toast>webworks run

Prior to executing webworks run, I modified the index.html file at the root www folder to define the showCustomToast function. I did this right before the existing call to app.initailize() as follows.

 

<script type="text/javascript">
	function showCustomToast() {
		var message = "This is my toast!",
			buttonText = "Click Me",
			toastId,
			onButtonSelected = function () {
				console.log('Button was clicked for toast: ' + toastId);
			},
			onToastDismissed = function () {
				console.log('Toast disappeared: ' + toastId);
			},
			options = {
				buttonText : buttonText,
				dismissCallback : onToastDismissed,
				buttonCallback : onButtonSelected
			};
		toastId = blackberry.ui.toast.show(message, options);
	}
	app.initialize();
</script>

 

Finally, inside of index.js, I waited for deviceready to trigger before displaying my Toast as follows:

 

    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
		showCustomToast();
    }

 

Upon the application launching, the Toast was displayed, and I could press the button. With Web Inspector confirmed, I could see that the Toast events were fired:

 

Received Event: deviceready index.js:47
Button was clicked for toast: 1 index.html:44
Toast disappeared: 1 index.html:47

 

Could you give these steps a try and confirm whether you see the same?

 

Note that, once your application launches, you may not be able to connect Web Inspector in time. You can work around this by inserting an alert('halt'); before the call to showCustomToast, and connecting Web Inspector before clearing the alert.

 

Or, once Web Inspector is connected, you can press ctrl+r in Web Inspector to reload the page, allowing the console to log everything from startup, including the Toast events.

 

 


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.