Search code examples
phplaravellaravel-5.8sweetalertsweetalert2

SweetAlert2: Unknown parameter "onBeforeOpen"


I'm using Laravel 5.8 and Sweetalert v2 and I tried firing this alert with it at the Blade:

Swal.fire({
    title: '<h4 style="color: #0c5460;">Updating user status</h4>',
    html: '<h5 style="color: #0c5460">Wait...</h5>',
    width: 400,
    padding: '1em',
    background: '#fff url(/images/cream_pixels.png)',
    timer: 1000,
    onBeforeOpen: () => {
        Swal.showLoading()
    },
});

And it popups properly but does not show the loader and shows me this error at the Console:

SweetAlert2: Unknown parameter "onBeforeOpen"

So what's going wrong here?


Solution

  • Use didOpen: Asynchronously runs after the popup has been shown on screen. Provides popup DOM element as the argument

                  Swal.fire({
                    didOpen: () => {
                      Swal.showLoading();
                    }
                  })