mistic100 / Bootstrap-Confirmation

Bootstrap plugin for on-place confirm boxes using Popover
http://bootstrap-confirmation.js.org
307 stars 124 forks source link

dispose doesnt work properly #140

Open Gawrion opened 3 years ago

Gawrion commented 3 years ago

Hi Mistic!

jQuery 3.6.0, Bootstrap 4.3.1, popper 1.14.7 Bootstrap Confirmation 4.2.1

After using dispose method on created instance its not possible to initialize new instance of confirmation. Example of bug:

<link rel="stylesheet" href="\css\bootstrap.css">
<script src="/js/jquery.js"></script>
<script src="/js/popper.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/bootstrap-confirmation.js"></script>

<button class="btn btn-default btn-sm btn-success " data-toggle="confirmation" id="btn-1">BTN1</button><br>
<button class="btn btn-default btn-sm btn-success " data-toggle="confirmation" id="btn-2">BTN2</button><br>
<button class="btn btn-default btn-sm btn-success " data-toggle="confirmation" id="btn-3">BTN3</button><br>

<script>
    confirmation();

    function confirmation() {
        let confirmOptions1 = {
            rootSelector: '[data-toggle=confirmation]',
            title: 'OPCJA 1',
        }
        let confirmOptions2 = {
            rootSelector: '[data-toggle=confirmation]',
            title: 'OPCJA 2',
        }
        // using popover works fine; using confirmation extension not working
        let confirmationInstance = $('[data-toggle=confirmation]').confirmation(confirmOptions1);

        $('#btn-1').confirmation('dispose');

        // new instance on #btn-1 after dispose works only with popover
        $('#btn-1').confirmation(confirmOptions2);
    }
</script>
Gawrion commented 3 years ago

Quick (but i don't know if not also buggy) workaround is to .removeData and remove event handler (.off) from element before settin new instance:

            $('#smietnik-btn-1').removeData();
            $('#smietnik-btn-1').off();
            $('#smietnik-btn-1').confirmation(confirmOptions2);