Menu icon Foundation
reveal - firing callback

Hi,
I'm trying to use reveal-modal as confirmation window to call ajax. i have button and when every next click "callback fired multiple times" and nuber increasing.
is anyway to prevent that?
thanks

$('button[name="confirm"]').click(function(ev){
    ev.preventDefault();
    var message= "message";
    confirmA(message,function(ev){
             alert("call");
             // ajax call 
    });      
});            
                    
function confirmA(message,callback){ 
    $('[data-reveal]').foundation('reveal','open',{});
    $(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
        $("button.yes").click(function(){
            alert(message);
            callback.call();
            $('[data-reveal]').foundation('reveal','close');
        });
    });
};

reveal

Hi,
I'm trying to use reveal-modal as confirmation window to call ajax. i have button and when every next click "callback fired multiple times" and nuber increasing.
is anyway to prevent that?
thanks

$('button[name="confirm"]').click(function(ev){
    ev.preventDefault();
    var message= "message";
    confirmA(message,function(ev){
             alert("call");
             // ajax call 
    });      
});            
                    
function confirmA(message,callback){ 
    $('[data-reveal]').foundation('reveal','open',{});
    $(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
        $("button.yes").click(function(){
            alert(message);
            callback.call();
            $('[data-reveal]').foundation('reveal','close');
        });
    });
};
Dominik Scholz over 5 years ago

Hi there,

we are having quite the same problem here and there's still no solution in sight. it seems to be all about Reveal counting how often it has been opened and then firing its open event as many times as you have opened it before.

We have got a jQuery datepicker here, which is permanently visible and fires a select event whenever you click on a single day. That select event opens a Reveal modal window, but each time when you select two or more days in a row, their select events get fired 2/3/4/5/x times - depending on how often the modal showed up before.

By the way, this is not a datepicker issue as we have been using VEX before and it all worked fine. ;-)

Is anyone experiencing a similar behavior or can give us a hint?

Thanks very much
Dominik

Dominik Scholz over 5 years ago

We have managed to solve this problem in the meantime. It was caused in part by our javascript (cumulation of event handler definitions), but apparently there is a little bug in the current version of Reveal, too.

As to the documentation, the event bindings of Reveal have been namespaced shortly. The older ones are still present for legacy reasons, but will be removed in future versions of Foundation. If you use those new ones like "close.fndtn.reveal", the related event is fired TWICE - but if you use the old one like "close", then the event is fired only once (what would be the expected behaviour).

Maybe someone else can leverage this information, too. ;-)

Kyle over 5 years ago

Hi Dominik, thanks for your reply. This just helped me out.

Rosario Garcia de Zuniga about 5 years ago

Hi all,

Thanks a lot for your post. I am experiencing the same problem, which is rather inconvenient, especially if you have a form in the modal, if you open and close it several times as Dominik mentioned in his post, this will result in several POSTs to the server :(

Hopefully they fix this problem soon!

l3x over 4 years ago

For the "twice firing" problem maybe this will be useful: http://foundation.zurb.com/forum/posts/26190

Dima Tsvetkov about 3 years ago

Here is my workaround to this problem.

https://codepen.io/dimatsvetkov/pen/EyvqaA