Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

Redirect inside function requires 2 button clicks, why?

Hi

I am having an issue with redirecting to a different page from within a function, that is called on a button press.

The function runs as it should no problem, but the redirect does not work on first click, you have to click the button a second time for the redirect?

The redirect is: Apperyio.navigateTo('Pay');

Any idea why I have to click the button twice?

Here is the function, which is called on the button press event!

Note: I am using the web interface and NOT on a mobile device!

pre
var service = new google.maps.DistanceMatrixService();

var origin = {lat: origLat, lng: origLong};
var destination = dest;
service.getDistanceMatrix(
{
origins: [origin],
destinations: [destination],
travelMode: google.maps.TravelMode.DRIVING,
avoidHighways: false,
avoidTolls: false,
unitSystem: google.maps.UnitSystem.IMPERIAL
},
callback
);

function callback(response, status) {

Code: Select all

 var orig = document.getElementsByClassName("orig"), 
   dest = document.getElementsByClassName("dest"), 
   dist = document.getElementsByClassName("dist"); 

if(status=="OK") {

Code: Select all

   orig.value = response.originAddresses[0]; 
   dest.value = response.destinationAddresses[0]; 
   dist.value = response.rows[0].elements[0].distance.text; 

   mileCostAmt = parseFloat(dist.value) * 3.14; 
   totalCost = parseFloat(mileCostAmt) + 75; 
   totalCost = totalCost.toFixed(2); 
   $scope.PayDetails.amount = totalCost; 

   Apperyio.navigateTo('Pay');  // Issue with this redirect 

} else {
alert("Sorry, we couldn't find that destination, please try again!");
}
}
/pre

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Redirect inside function requires 2 button clicks, why?

Hello,

Is the callback function called here?

Please check if there are any errors in the browser console. You can learn here: https://docs.appery.io/docs/using-bro... how to open the console.

Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

Redirect inside function requires 2 button clicks, why?

Yes. The callback function is called.

The variables etc are all populated within the if(status=="ok") block, its just ignoring the redirect?!?!

Its very odd!

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Redirect inside function requires 2 button clicks, why?

Yes, some popups can reflect on the function order. Please provide us with a [public app link] (https://docs.appery.io/docs/testingan...) and exact steps to reproduce this problem.

Return to “Issues”