Page 1 of 1

Redirect inside function requires 2 button clicks, why?

Posted: Thu Jan 31, 2019 4:36 pm
by Alan Smith

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


Redirect inside function requires 2 button clicks, why?

Posted: Fri Feb 01, 2019 10:18 am
by Serhii Kulibaba

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.


Redirect inside function requires 2 button clicks, why?

Posted: Fri Feb 01, 2019 10:41 am
by Alan Smith

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!


Redirect inside function requires 2 button clicks, why?

Posted: Mon Feb 04, 2019 4:29 pm
by Serhii Kulibaba

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.