Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of buttons in navigator.notification.confirm in PhoneGap framework

I am using the following piece of code in my PhoneGap app.

        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 coming properly as "Cancel" and "Ok" in iPhone. But for Android the order of buttons are reversed. Its coming as "Ok" and then "Cancel".

As a result the button indices are getting changed in the callback method.

iPhone Screenshot android Screenshot

All suggestions are welcomed :)

Thanks,

like image 969
Biranchi Avatar asked Nov 19 '25 09:11

Biranchi


2 Answers

Try using 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 here is how you would 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);
like image 106
Zorayr Avatar answered Nov 22 '25 00:11

Zorayr


This is not an Issue. What ever you are getting is native behavior of respective platform. In iOS, "Cancel" button will appear on left side and in Android you will get it on Right side. If the problem is only button index, then you can handle it in your code. But you cannot change the sequence of the buttons on screen.

like image 37
Tapas Jena Avatar answered Nov 22 '25 00:11

Tapas Jena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!