notiflix / Notiflix

Notiflix is a pure JavaScript library for client-side non-blocking notifications, popup boxes, loading indicators, and more that makes your web projects much better.
https://notiflix.github.io
MIT License
635 stars 55 forks source link

CLOSED: Confirm dialog will appear again when go to the same page #23

Closed nyrf closed 4 years ago

nyrf commented 4 years ago

Thanks for your great library.

Kapture 2020-05-23 at 3 22 49

furcan commented 4 years ago

Hi,

Firstly thanks for using the Notiflix.

Could you please share an example of the code about this. I can not get the issue by this GIF so I can not reproduce it.

Thank you.

nyrf commented 4 years ago

@furcan Sorry, i found out it was caused by turbolinks. i've add the codes and it works fine now, thanks.

  document.addEventListener('turbolinks:before-cache', () => {
      if ($('#NotiflixConfirmWrap').length > 0) {
        $('#NotiflixConfirmWrap').remove()
      }
  }
furcan commented 4 years ago

@nyrf hi again,

All Notiflix modules have CSS animations to show or hide(also remove) themselves.

So, the Confirm module has 300 milliseconds of delay (cssAnimationDuration, you can look at the documentation page for more info). I think your navigation tool changing the route before the Confirm module removed.

Probably your solution works fine, but I can recommend adding a timeout function to the Confirm module callback function to wait for removed.

Just an example:

 Notiflix.Confirm.Show( 
    'Notiflix Confirm', 
    'Do you agree with me?', 
    'Yes', 
    'No', 
    function(){ // Yes button callback 

        var routingTimeout = setTimeout(function(){ 

            // your turbolink codes etc...

            clearTimeout(routingTimeout);
        }, 360); // => delay removing the Confirm module.

    }, 
    function(){ 
        // No button callback 
    } 
); 

Thanks.