For some reason when I try to reopen the first modal (editModal1) from the second modal via (data-bs-target="editModal1") I get the following error:
modal.js:332 Uncaught TypeError: Cannot read properties of undefined (reading 'classList')
at De._isAnimated (modal.js:332:26)
at De._initializeBackDrop (modal.js:205:24)
at new De (modal.js:82:27)
at Function.getOrCreateInstance (base-component.js:55:41)
at HTMLButtonElement.<anonymous> (modal.js:434:22)
at HTMLDocument.n (event-handler.js:120:21)
_isAnimated @ modal.js:332
_initializeBackDrop @ modal.js:205
De @ modal.js:82
getOrCreateInstance @ base-component.js:55
(anónimo) @ modal.js:434
n @ event-handler.js:120
This is my code:
$(document).ready(function() {
});
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<table id="itemsTable" class="display nowrap" width="100%">
<thead>
<tr>
<th>Column1</th>
<th>Column2</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr>
<td>value1</td>
<td>value2</td>
<td>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#editModal1">
EDIT
</button>
</td>
</tr>
<!-- modal -->
<div class="modal fade" id="editModal1" tabindex="-1" aria-labelledby="newITTLModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" id="newTaskModalHeader">
<div class="col-8">
<h5 class="modal-title" id="newTaskModalLabel">Edit Modal</h5>
</div>
<div class="col-4">
<button type="button" class="btn btn-secondary new-task-dismiss rounded-0" data-bs-toggle="modal" data-bs-target="#cancelModal" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary rounded-0">Save</button>
</div>
</div>
<div class="modal-body">
<div class="row">
<div class="col-5 mt-3">
<ul class="list-unstyled">
<li class="mt-3">
<div class="row">
<div class="col-sm ph-tabs-field-label">
Name <span style="color:red;">*</span>
</div>
<div class="col-sm">
<input type="text" name="name" class="form-control" aria-label="Name" required>
</div>
</div>
</li>
</ul>
</div>
<div class="col mt-3">
</div>
</div>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<!-- end modal -->
<!-- cancel modal -->
<div class="modal fade" id="cancelModal" tabindex="-1" aria-labelledby="Cancel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<h4 class="text-center" style="color:#013B4B;">Are you sure you want to cancel?</h4>
</div>
<div class="row mt-4">
<div class="col-3">
</div>
<div class="col-6 d-flex align-items-center justify-content-center">
<button type="button" class="btn btn-success btn-lg rounded-0" data-bs-dismiss="modal">Yes</button>
<button type="button" class="btn btn-danger btn-lg rounded-0" data-bs-target="editModal1" data-bs-toggle="modal" data-bs-dismiss="modal">No</button>
</div>
<div class="col-3">
</div>
</div>
</div>
</div>
</div>
</div>
<!-- end cancel modal -->
</tbody>
</table>
I want to reopen the first modal if I click "Are you sure you want to cancel? -> NO"
If I am not mistaken the problem is that when I click NO, editModal1 no longer exists in the DOM and that’s why I get that error but I don’t know how to fix it.
I’ve been looking at some previous stackoverflow questions about how to nest/concatenate multiple modals, unfortunately I couldn’t find a solution.
