5

After closing of the modal I force the browser to scroll to the top of the page to see any error messages. After integrating the SweetAlert2 module to confirm submission the application will auto scroll back down to the submit button now after closing instead of staying at the top.

submit() {
    swal({
      title: "Submit application",
      html: "All submissions are final",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "Yes, delete it!",
      cancelButtonText: "Cancel"
    }).then(result => {
          window.scrollTo(0,0);
        }
    );
  }

As you can see I'm trying to force the scroll to the top in multiple areas and this works, but then it snaps back to the bottom. Please see attached gif as demonstration.

Scrolling error

Any ideas on how to fix this?

Bootstrap 4

SweetAlert2 7.28.2

EDIT: Reproduced in simple JSFiddle https://jsfiddle.net/s8f12xad/

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
Raymond Holguin
  • 1,050
  • 2
  • 12
  • 35

2 Answers2

8

didClose parameter is what you need in this case:

Swal.fire({
  didClose: () => window.scrollTo(0,0)
})
Limon Monte
  • 52,539
  • 45
  • 182
  • 213
  • I have a similar problem when the button is semi visible at the bottom of the page when opened.. when it closes it scrolls the page so that the WHOLE button is visible. I don't want it to move to the top, or to the elem.. I just want it to close. Any suggestions? PS. Been reading through the Git issues, great to see such fast responses from you, awesome work and great plugin! – Latchy Mar 08 '19 at 03:35
1

Really ? the author answer you, thats its great !!!

I had a redirection problem which consisted of losing the navigation scroll, I solved it with this code:

Swal.fire({
    title: 'Example',
    type: 'success',
    onAfterClose: () => window.location.href = "url"
});

Thank you.

Limon Monte
  • 52,539
  • 45
  • 182
  • 213