I know this question was asked many times but I think I've tried everything... I have a bootstrap dropdown and the dropdown item should open a modal. But it is not showing. Nothing happens when the button is clicked.. The modal works as expected when I click it with a normal button instead of a dropdown button. FYI, the html below is reiterated in a for loop (for every comment in a post). Not sure if that matters? maybe the dropdown needs a unique id?
<div class="dropdown" style="float:right;">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
•••
</button>
<div class="dropdown-menu">
<button type="button" class="dropdown-item delete-btn{{ comment.id }}" data-toggle="modal" data-target="#commentdeleteModal-{{ comment.id }}">
Delete
</button>
</div>
</div>
<div class="modal" id="commentdeleteModal-{{ comment.id }}" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete the comment? <br>
This can’t be undone.</p>
</div>
<div class="modal-footer">
<form action="{% url 'comment-delete' comment.id %}" method="POST" class="comdelete-form" id="{{ comment.id }}">
{% csrf_token %}
<div class="form-group">
<button class="btn btn-danger" type="submit">Delete</button>
<button type="button" class="btn btn-secondary closebtn" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
</div>
seems like an easy problem.. my head hurts.. thx
I'd rather change instead of a <button>
with <a>
. Let me be more clear:
<div class="dropdown" style="float:right;">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
•••
</button>
<div class="dropdown-menu">
<a href="#" class="dropdown-item delete-btn{{ comment.id }}" data-toggle="modal" data-target="#commentdeleteModal-{{ comment.id }}">
Delete
</a>
</div>
Let me know if that did the trick
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.