1

i have funny problem in bootstrap 5.0.2

I have to double-click the button (data-bs-dismiss) to close the modal

Important note:‌I use many modal in page, But they open depending on the need

<div class="modal" id="open-rating-modal-for-order" tabindex="-1" aria-labelledby="open-call-modal" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <form method='POST' onsubmit="return validate_rating_modal()">
        <input type='hidden' name='page' value='submit-rate' />
        <input type='hidden' name='csrf_token' value="{$csrf_token}" />
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">
            rates
          </h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
    </div>
  </div>
</div>
MarioG8
  • 5,122
  • 4
  • 13
  • 29

1 Answers1

0

I just applied the fade class style to the first container and added a <button> element to trigger the modal to pop up and it worked successfully.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <title>Document</title>
</head>

<body>
    <div class="d-grid gap-2">
        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#open-rating-modal-for-order">
        Open Modal
        </button>
    </div>

    <div class="modal fade" id="open-rating-modal-for-order" tabindex="-1" aria-labelledby="open-call-modal"
        aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <form method='POST' onsubmit="return validate_rating_modal()">
                    <input type='hidden' name='page' value='submit-rate' />
                    <input type='hidden' name='csrf_token' value="{$csrf_token}" />
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">
                            Rates
                        </h5>

                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous">
    </script>
</body>
</html>
Sercan
  • 4,739
  • 3
  • 17
  • 36
  • thanks dear uses this $(this).off('hidden.bs.modal'); when remove this i can,t close modal and when use this twice click –  Dec 20 '21 at 12:31
  • Your question is not clear! Do you have to double click the "close" ` – Sercan Dec 20 '21 at 12:50
  • I found the problem! The two modals were opening together and because it was hidden under this, I could not see that it was solved. Thank you dear friend. –  Dec 20 '21 at 13:14