Search code examples
twitter-bootstrapbootstrap-4confirmation

Bootstrap 4 Confirmation is not working, what is wrong with it?


I added bootstrap 4 confirmation in my project but this is not working even I added sources etc...

What is wrong with it?

My code:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap-confirmation2/dist/bootstrap-confirmation.min.js"></script>


<div class="m-4">
<button class="btn btn-primary" data-toggle="confirmation">Confirmation</button>
</div>

I'm using this "BS-4-Confirmation" confirmation plugin...


Solution

  • You need to enable confirmations via javascript like below.

    $('[data-toggle=confirmation]').confirmation({
       rootSelector: '[data-toggle=confirmation]'
    });
    

    I've changed your snippet to work and It will work.

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-confirmation2/dist/bootstrap-confirmation.min.js"></script>
    
    <div class="m-4">
    <button class="btn btn-primary" data-toggle="confirmation">Confirmation</button>
    </div>
    
    <script>
    $('[data-toggle=confirmation]').confirmation({
       rootSelector: '[data-toggle=confirmation]'
    });
    </script>