DarkKnightFan
DarkKnightFan

Reputation: 1953

Extjs confirm box callback handling

In my ExtJs code I am checking the value of a warning flag.

If the flag is set I want to show a confirm (OKCANCEL) box to the user where I ask the user if he wants to proceed even though there is a warning.

Now just like any confirm box if the user clicks OK, the code should proceed to the next command in sequence and if he clicks CANCEL the code should return.

Following is my code:

if(warning){
    Ext.MessageBox.show({
        title: 'Icon Support',
        msg: 'Are you sure you want to proceed?',
        buttons: Ext.MessageBox.OKCANCEL,
        icon: Ext.MessageBox.WARNING,
        fn: function(btn){
            if(btn == 'ok'){
            // go to the alert statement below.
            } else {
                return;
            }
        }
    );

    alert('wants to proceed ahead'); //if user clicks OK then come here
} 

Now the problem I am facing is when the code enters the if block it shows the message box and then it alerts wants to proceed ahead.

I can stop that from happening by putting a return; statement before the alert().

But how do I go to the alert statement after the user clicks OK button?

Upvotes: 1

Views: 14806

Answers (2)

Sergey92zp
Sergey92zp

Reputation: 589

Callbacks it is event driven architecture, and JavaScript it is interpreted programming language.

So the best way will be

function SomeFunc(){
//some code 
}
if(warning){
    Ext.MessageBox.show({
        title: 'Icon Support',
        msg: 'Are you sure you want to proceed?',
        buttons: Ext.MessageBox.OKCANCEL,
        icon: Ext.MessageBox.WARNING,
        fn: function(btn){
            if(btn == 'ok'){
            SomeFunc();
            } else {
                return;
            }
        }
    });
} 

Upvotes: 6

charCo
charCo

Reputation: 31

Something to note, I think your alert may just be an example of code that you are wanting to use as a placeholder for real code processing.

But just in case it's the first line of more code, a plain alert will block the processing of the browser and remove focus from the current window.

http://www.w3schools.com/jsref/met_win_alert.asp

I second Sergey's reply and just had to rearrange code to correctly get callback functions in place, now that a proceed through the message was needed on "Ok". I considered the looping but that was not safe.

Upvotes: 0

Related Questions