admin管理员组

文章数量:1387347

I want to create an alert similar to the ajax-example, but allowing outside click dismiss before confirming. After the user clicks confirm I would like to disallow outside click until the operation is finished.

Setting the config variable allowOutsideClick to false like in the example will never allow outside click and I don't see a valid method in the docs to achieve this behavior programatically.

I want to create an alert similar to the ajax-example, but allowing outside click dismiss before confirming. After the user clicks confirm I would like to disallow outside click until the operation is finished.

Setting the config variable allowOutsideClick to false like in the example will never allow outside click and I don't see a valid method in the docs to achieve this behavior programatically.

Share Improve this question edited Jan 26, 2018 at 8:02 Limon Monte 54.5k49 gold badges190 silver badges220 bronze badges asked Dec 21, 2017 at 12:29 angrykoalaangrykoala 4,0948 gold badges35 silver badges59 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

It's possible to pass the function to the allowOutsideClick parameter:

allowOutsideClick: () => { 
  // add your logic here and return boolean 
}

Your case:

Swal.fire({
  title: 'Submit email to run ajax request',
  input: 'email',
  showLoaderOnConfirm: true,
  preConfirm: (email) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve()
      }, 3000)
    })
  },
  allowOutsideClick: () => !swal.isLoading()
})
<script src="https://cdn.jsdelivr/npm/sweetalert2@11"></script>

本文标签: javascriptSweetAlert2 disallow outside click after confirmStack Overflow