PreventDefault SweetAlert2

0

I have this function that overrides all my native JS alerts, however, sweetAlert does not automatically give preventDefault , which causes the next lines of code to run immediately after the alert is displayed. Is there a way to get event and give preventDefault without changing the method signature to pass the event?

function alert(mensagem, titulo = 'Teste', tipo = 'info')
{
    // event.preventDefault();
    if(typeof(swal) != 'undefined') {
        swal({
            html: mensagem,
            title: titulo,
            type: tipo,
            width: '24rem',
        }).then((result) => {
            return result.value;
        });
    }
    else {
        alert(mensagem);
    }
}

Explaining better: when I finish a PHP function I return a alert('Operação realizada com sucesso') for example, and then redirect to another page. With the native alert it expects me to click OK to direct. Now with this function I created, it shows the alert and redirects right away.

    
asked by anonymous 13.11.2018 / 13:42

0 answers