Jump to content

Recommended Posts

Hi guys,

When I try to open a Bootstrap 5 Modal I get the following error in console:

vendor.bundle.base.js:9 Uncaught TypeError: Cannot read properties of undefined (reading 'backdrop')
    at On._initializeBackDrop (vendor.bundle.base.js:9:52555)
    at new On (vendor.bundle.base.js:9:51462)
    at On.getOrCreateInstance (vendor.bundle.base.js:9:7913)
    at HTMLAnchorElement.<anonymous> (vendor.bundle.base.js:9:55451)
    at HTMLDocument.n (vendor.bundle.base.js:9:4238)

Here is the link to open the modal:

<li class="nav-item"> <a class="nav-link" data-bs-toggle="modal" data-bs-target="#websettingsModal" href="#"><?php echo lang('WEBSITE_SETTINGS'); ?></a></li>

And the modal itself:

<div class="modal fade" id="websettingsModal" tabindex="-1" aria-labelledby="websettings" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="websettings">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

If anyone could help that would be great.

Thanks,

Dan

15 minutes ago, requinix said:

I had a look at those. Funny thing is, and I should have mentioned this, I have other Modals, with same links and same modal types that open with no issue. Just this one that is throwing that error.

Just now, requinix said:

Then, as before, there's something wrong with this particular modal or its setup.

Yeah I'm guessing that too. However, strange as it may seem, I created a new empty Modal from Bootstrap website and a new link to open that Modal, with a new ID etc, and same issue. It's really strange how the other Modals, which are called from the same file, modals.php, are working fine.

Ok, the issue only seems to happen when I wrap the Modal in php:


  if(ISSET($_POST['websettings_save'])){
	$charter_max = $_POST['charter_max'];
 
    $sql = "UPDATE web_settings SET charter_max='$charter_max'";

if (mysqli_query($conn, $sql)) {
$msg = '<div id="msg"><h4 class="text-success">Website settings updated successfully!</h4></div>';

} else {
  $msg = '<div id="msg"><h4 class="text-danger">Error updating Website settings: ' . mysqli_error($conn) . '</h4></div>';
}

  }
 // SELECT FROM Web Settings
$sql = "SELECT * FROM web_settings";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
  ?>
<div class="modal fade" id="websettingsModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="exampleModalLabel"><?php echo lang('WEB_SETTINGS'); ?></h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
	  <form method="POST">
      <div class="modal-body">
        <p class="text-muted"><?php echo lang('UPDATE_WEB_SETTINGS'); ?></p>
          <div class="mb-3">
            <label for="charter_max" class="col-form-label"><?php echo lang('CHARTER_MAX'); ?>:</label>
            <input type="text" class="form-control" name="charter_max" id="charter_max" value="<?php echo $row['charter_max']; ?>">
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-bs-dismiss="modal"><i class="fa fa-close"></i> <?php echo lang('CLOSE'); ?></button>
        <button type="submit" onclick="javascript:window.location.reload()" name="settings_save" id="save" class="btn btn-success"><i class="fa fa-save"></i> <?php echo lang('SAVE'); ?></button>
      </div>
	  </form>
    </div>
  </div>
</div>

<?php
  }
}
  ?>

But, other Modals are done the same way with no issue.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.