Ordering buttons in navigator.notification.confirm in the PhoneGap system.
I am using the following piece of code in a PhoneGap application.
function registrationCallBack(button){
if(button == 2) {
window.location.href = "login.html";
}
}
navigator.notification.confirm("Are you sure ?", registrationCallBack, "Confirmation", "Cancel, Ok");
The order of the buttons is correct, like "Cancel" and "OK" in the iPhone. But for Android the order of the buttons is reversed. His coming is "Ok" and then "Cancel".
As a result, the button indices are changed in the callback method.
All suggestions are welcome :)
Thank,
+3
source to share
4 answers
Try the following solutions:
function showConfirm(message, callback, buttonLabels, title){
//Set default values if not specified by the user.
buttonLabels = buttonLabels || 'OK,Cancel';
title = title || "default title";
//Use Cordova version of the confirm box if possible.
if(navigator.notification && navigator.notification.confirm){
var _callback = function(index){
if(callback){
callback(index == 1);
}
};
navigator.notification.confirm(
message, // message
_callback, // callback
title, // title
buttonLabels // buttonName
);
//Default to the usual JS confirm method.
}else{
invoke(callback, confirm(message));
}
}
And this is how you use it:
var message = "Would you like to proceed?";
var title = "Important Question";
//The first element of this list is the label for positive
//confirmation i.e. Yes, OK, Proceed.
var buttonLabels = "Yes,No";
var callback = function(yes){
if(yes){
alert('Proceed');
}else{
alert('Do Not Proceed');
}
};
showConfirm(message, callback, buttonLabels, title);
+2
source to share
It's not a problem. Whatever you get is the native behavior of the respective platform. On iOS, the Cancel button will appear on the left side, while on Android you will get it on the right side. If the problem is only the button index, you can handle it in your code. But you cannot change the sequence of buttons on the screen.
+2
source to share