79594329

Date: 2025-04-26 19:47:36
Score: 0.5
Natty:
Report link

This is a very old question. SweetAlert may have been non blocking originally. I have recently (April 25, 2025) downloaded it. I am able to have it block, be synchronous. It uses Promises.

async function foo()
{
    if ( await yesno( "Answer Yes or No" ) {
        // They answered YES
    } else {
        // They answered NO
    }
}

async function yesno( question )
{
    var rtn;
    await swal({
        closeOnEsc: false,
        closeOnClickOutside: false,
        text: question,
        buttons: { 
            no:  { text: "No",  value: 0 },
            yes: { text: "Yes", value: 1 },
          },
    }).then( value => {
        switch (value) {
            case 1:
                rtn =  true;
                break; 
            case 0: 
            default:
                rtn =  false;
                break; 
        }
    });
    return rtn;
}   
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: David B