How can I have impromptu not continue until submit is done and exits

89 Views Asked by At

I'm using the jQuery impromptu library and not understanding the async nature of it. I've got some code below that I want to redirect after the prompt is run. I don't want the next line of code to execute if my data.redirectPage statement is true.

               success: function (data) {
                    if (data.redirectPage == "hackathonregistration") {
                        $.prompt("Your code has been accepted and you will now be redirected to the hackathon registration page",
                        {
                            submit: function() {
                                window.location.href = "/Register/hackathon";
                            }
                        });
                    }
1

There are 1 best solutions below

0
Louys Patrice Bessette On

From what I read fast about Impromptu, your code looks ok.
Except the missing } to close your success function... ;)

AND no buttons on the submit you try to trigger.
That is an important AND.

Try this :

success: function (data) {
    console.log(data.redirectPage);
    if (data.redirectPage == "hackathonregistration") {
        $.prompt("Your code has been accepted and you will now be redirected to the hackathon registration page",
        {
            buttons: { "Yes": true, "No": false },
            submit: function(e,v,m,f) {
                // use e.preventDefault() to prevent closing when needed or return false.
                // e.preventDefault();
                console.log("Value clicked was: "+ v);
                if(v){
                    window.location.href = "/Register/hackathon";
                }
            }
        });
    }
}

I suppose v is the bolean true/false.
Like said, I read real fast on Impromtu.

Personnaly, I use SweetAlert. Look for it as an alternative... May be easier.