Wait on SweetAlert response
<p>I currently have a function that asks the user for confirmation when changing a value in a dropdown. This works fine using the standard <code>JavaScript</code> <code>confirm()</code>. Here's the <a href="https://jsfiddle.net/1gwLggfm/" rel="nofollow noreferrer">fiddle</a>.</p>

<pre><code>var prev_val;
$('#dropdownId').focus(function () {
    prev_val = $(this).val();
}).change(function () {
    $(this).blur();
    var success = confirm('Are you sure you want to change the Dropdown?');
    if (success) {
        // Proceed as normal.
    } else {
        // Reset the value &amp; stop normal event
        $(this).val(prev_val);
        return false;
    }
});
</code></pre>

<p>But when using <a href="http://t4t5.github.io/sweetalert/" rel="nofollow noreferrer"><code>SweetAlert</code></a>, the change event always takes place before I'm able to confirm/cancel. Meaning, when I select a new value, and pressing "cancel", it does not stop the event and reset the previous value. Which it does with the regular <code>JavaScript</code> <code>confirm</code> dialog.</p>

<pre><code>var prev_val;
$('#' + dropdownId).focus(function () {
    prev_val = $(this).val();
}).change(function (e) {
    $(this).blur();
    return swal({
        title: "Are you sure?",
        text: "Do you want to change the dropdown?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes",
        cancelButtonText: "No",
        closeOnConfirm: true,
        closeOnCancel: true
    },
            function (isConfirm) {
                if (isConfirm) {
                    e.preventDefault();
                    return true;
                } else {
                    $(this).val(prev_val);
                    return false;
                }
            });
});
</code></pre>

<p>It might also be interesting to note that this <code>JavaScript</code> might even be invalid (pretty new to <code>JavaScript</code>), e.g. returning from the <code>confirm</code> function and from the <code>swal</code> function not functioning.</p>

<p>However, after Googling around, I found people with similar issues.</p>

<ul>
<li><a href="https://stackoverflow.com/questions/31136889/how-to-use-confirm-using-sweet-alert">how-to-use-confirm-using-sweet-alert</a></li>
<li><a href="https://stackoverflow.com/questions/31430930/how-to-run-a-sweetalert-instead-of-default-javascript-confirm-method">how-to-run-a-sweetalert-instead-of-default-javascript-confirm-method</a></li>
</ul>

<p>But that seems a bit hacky since it's preventing any action, but when selecting confirm he re-creates the function that should have been called by default. Which seems like quite a hack for something so simple.</p>

<p>Any possibility of the <code>SweetAlert</code> just acting like a regular <code>confirm</code> dialog?</p>