Bootstrap Confirmation Canceling Confirmation On Click

269 Views Asked by At

I am trying like this. My goal is cancel confirmation and alert information.

    var item = $('[data-toggle=confirmation]');
    item.on('confirmed.bs.confirmation', function(e,v) { 

       if(everyThingIsOkey){

         go event ...
       }
       else{
        e.stopImmediatePropagation(); //not working
        e.preventDefault(); //not working
        //cancel confirmation and alert information.
       }
    });
    item.confirmation({ btnOkLabel: 'Yes', btnCancelLabel: 'No', title: 'Are you sure?' });

I am using Bootstrap Confirmation 2.4.0 and Bootstrap v3.3.6

Here is bootstrap-confirmation examples.

My html for the problem :

<a id="cphBody_grdPopulasyon_lnkOnayla_0" class="btn btn-success btn-xs" data-toggle="confirmation" href="javascript:__doPostBack('ctl00$cphBody$grdPopulasyon$ctl02$lnkOnayla','')" style="cursor: pointer" data-original-title="" title="" aria-describedby="confirmation108897"><i class="fa fa-check"></i></a>
1

There are 1 best solutions below

1
On

To make confirmation work properly you should follow two rules:

  1. Enable confirmations via JavaScript:
$('[data-toggle=confirmation]').confirmation({
   rootSelector: '[data-toggle=confirmation]',
   // other options
});
  1. In order to have the good behavior, the plugin must be initialized before manually attaching event listener (with $.on())