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.

iPhone Screenshotandroid Screenshot

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


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


I have not tried this on iphone. But tried it in android. I have not encountered such problems with telephony 1.4.1. Therefore, I suggest you update your phone version. The problem you are facing may be fixed in a new release. :)

0


source


I was a little late but I had the same problem, however I did it by changing them, so "Cancel" goes where "OK" and "Ok" goes where "Cancel". This worked for me.

0


source







All Articles