t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.4k stars 2.84k forks source link

If I replace a visible toast by creating a new swal it "adopts" the auto-closetimer of the former visible toast #846

Closed Snickbrack closed 6 years ago

Snickbrack commented 6 years ago

I have this function:

queueSwalToast: function (toastType, toastText) {
        //if toast is already shown then call setTimeout for a time 500 ms after the removal of the previous toast
        var timerEndTime = 3000;

        const toast = swal.mixin({
            toast: true,
            position: 'top-end',
            showConfirmButton: false,
            timer: timerEndTime
        });

        if (GlobalVariables._currentSwalEndTime != 0) {
            setTimeout(function () {
                if (!swal.isVisible()) {
                    console.log(swal.isVisible());
                    toast({
                        type: toastType,
                        title: toastText
                    })
                    GlobalVariables._currentSwalEndTime = Date.now() + timerEndTime;
                }
            }, GlobalVariables._currentSwalEndTime - Date.now() + 500);
        }
        else {
            if (!swal.isVisible()) {
                console.log(swal.isVisible());
                toast({
                    type: toastType,
                    title: toastText
                })

                GlobalVariables._currentSwalEndTime = Date.now() + timerEndTime;
            }
        }

    }

Which queues swal's by endtime. If I now create a normal swal for data presentation it does adopt the timer "endtime" of the former swal toast.

Swal code:

var inputOptions = new Promise((resolve) => {
            resolve(_markets)
        })

        const {value: _marketID} = await swal({
            title: 'Markt auswählen',
            input: 'radio',
            inputOptions: inputOptions,
            inputValidator: (value) => {
                return !value && 'Bitte einen Markt auswählen!'
            }
        })

If the new swal is created it auto-closes after 1-2 Seconds which could be the endtime of the toast swal.

But why?

limonte commented 6 years ago

Wrong repo, the issue should be reported here: https://github.com/sweetalert2/sweetalert2/issues