Costy
Costy

Reputation: 165

boxy.confirm don't wait for confirm

In case the close (X) is pressed, Boxy doesn't wait for a confirmation. Below is an example describing my problem:

$('form .close').click(function(event) {
    event.stopPropagation();
    Boxy.confirm("Are you sure ?", function() {
        alert('ok');
    });
    return false;
});

However, when the OK button is clicked, everything works as expected.

Why does this not work as expected in case the (X) is pressed?

Upvotes: 0

Views: 592

Answers (2)

Yury Tarabanko
Yury Tarabanko

Reputation: 45121

As I have already mentioned in my comment Boxy.confirm is async unlike native confirm. Your code will continue its execution without waiting for user to click OK or Cancel. That is why you need to perform the actual action inside confirm callback.

Consider the following code.

$('form .close').click(function(e){
    var form = $(this).closest('form');

    Boxy.confirm('Are you sure?', function() {
        form.remove(); //remove it only if user confirmed.    
    });

    form.append('<p>Close was clicked.</p>');

})

This code will append message every time user clicks close link. But the form will be actually removed only if user confirmed the action.

http://jsfiddle.net/tarabyte/972ak/4/

Upvotes: 0

Code.Town
Code.Town

Reputation: 1226

Please see this example that I made for you: http://jsfiddle.net/972ak/

$('form .close').click(function(event) {

            Boxy.confirm("Are you sure ?", function() {
                alert('ok');
            });
            return false;

    });

Boxy documentation says:

Boxy.confirm(message, callback, options) Displays a modal, non-closeable dialog displaying a message with OK and Cancel buttons. Callback will only be fired if user selects OK.

http://onehackoranother.com/projects/jquery/boxy/

Upvotes: 1

Related Questions