saribe / eModal

Easy Modal for bootstrap, is a simple way to create modal dialogs using javascript.
http://saribe.github.io/eModal
271 stars 97 forks source link

eModal.confirm why callback function start before click OK? #42

Closed Paplo22 closed 8 years ago

Paplo22 commented 8 years ago

Hi

$(document).on("click","."+deletebutton,function(){
            var id = $(this).attr("id");
            var options = {
                message: "The famous question?",
                title: 'Header title',
                size: eModal.size.sm,
                subtitle: 'smaller text header',
                label: "OK"   // use the positive label as key
            };
            eModal.confirm(options)
                .then(toastr.success('why? now....', 'WTF'));
        });

and the 'toastr' is used before it is confirmed .. :( why

FIX, CLOSE

saribe commented 8 years ago

because you must pass a function reference and not execute the function on the then. This is an Async code execution you should provide a callback.

         const referenceToOkFunction= function(value) { 
              toastr.success('why? now....', 'value);
         };
         const referenceToCanceFunction = referenceToOkFunction,bind(null, 'Pressed cancel');

         eModal.confirm(options)
              .then(referenceToOkFunction, referenceToCanceFunction);
        });