0

I am trying to use sweet alert to as a replacement for the standard JavaScript confirm dialog box. The issue I am experiencing is when I return the promise the method does not wait for the response it simply ends the tour.

I would like to see this method accept a promise and wait for the response. Is this possible?

I would expect after clicking no on the sweetAlert modal, that i would be returned to the tour as when using the standard javascript confirm('') method as shown here

Introjs().onbeforeexit(function() {

        var alertText;

    if (instance.data.whatstep < steps.length){
        alertText = 'Are you sure you want to leave the tour early'
    } else {
        alertText = properties.alert_text
    }
    
    var r = confirm (alertText)
    if (r == true){
        console.log('exit')

        if ( instance.data.whatstep < steps.length ){
            console.log('leaving early')
            instance.triggerEvent("user_left_tour")

        } else {
            console.log('not leaving early')
            instance.triggerEvent("user_finished_tour")
        }
        
        return r
        
    } else {
        console.log('dont exit')
        return r
    }

});

here is the 'onbeforeexit()' code I am trying to use that doesn't work

    Introjs().onbeforeexit(function() {
     const r = async function confirm(message) {
        return swal({
            text: 'are you sure',
            buttons: true
        });
    }
        console.log(r())
        return r()
    
    }).start();


Jared Gibb
  • 47
  • 5

1 Answers1

1

I think this is what you want

Swal.fire({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  icon: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.isConfirmed) {
    Swal.fire(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
}) 

This is avaliable in the SweetAlert 2
Here is the link for the same Link the example you are looking for is "A confirm dialog, with a function attached to the "Confirm"-button..."

Nishant S Vispute
  • 713
  • 1
  • 7
  • 21