Reputation: 301
How can I close the bootstrap modal after I click on the Delete
button? Here's my code:
<div id="media_delete_confirmation" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Confirmation</h4>
</div>
<form id="modal-form">
<div class="modal-body">
<input id="media_action" value="deleteMediaAction" type="hidden"/>
<p>Do you want to save changes you made to document before closing?</p>
<p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Keep</button>
<button type="button" class="btn btn-default" id="modal_delete">Delete</button>
</div>
</form>
</div>
</div>
</div>
and here's the other part:
$("#modal_delete").click(function() {
var id = $(".image-picker").val();
var media_action = $("#media_action").val();
$.ajax({
type: 'POST',
url: '?page=myMediaController&action=deleteMedia',
data: {'media_id' : id},
success: function(data) {
$("#media_delete_confirmation").modal("hide");
}
});
});
Upvotes: 13
Views: 38939
Reputation: 416
you can simply hide modal on submit $('#media_delete_confirmation').modal('hide'); //to hide modal
Upvotes: 1
Reputation:
first add a id or class in this submit button like closemodel. then add another id or class in this first div. then add this jquery code
<script>
$(document).ready(function() {
$('#closemodel').click(function() {
$('#CreateAccount1').modal('toggle');
});
});
</script>
Upvotes: 0
Reputation: 11
Just try on a <script>
before the end of your body writing this
$('#media_delete_confirmation').submit(function() {
$('#media_delete_confirmation').modal('hide');
});
Upvotes: 0
Reputation: 1
I just had the same problem. I was trying to close a modal window after submit. The only way that I could solve it was doing the following.
In the success function, I added this code via jQuery:
success: function(respuesta){
$('#btnGuardarCambios').attr("data-dismiss", "modal");
On the "save changes" button, I used the attr
method. If the ajax is successful, I just add a new attribute (data-dismiss
) and set the value of it (modal) else the modal won't disappear.
EDIT: This isn´t working on IE and Chrome, only works on Mozilla :c
Upvotes: 0
Reputation: 787
I had the same issue, and was able to get the modal dialog to close this way:
<div id="approveDialog" class="modal approveDialog hide">
<!-- various form elements -->
<div class="modal-footer pull-center">
<a href="#" data-dismiss="modal" aria-hidden="true" class="btn">Back to Listings</a>
<button id="submitApprove" class="btn btn-success">Shop</button>
</div>
</div>
$('button#submitApprove').on("click", function(event) {
// submit form via ajax, then
event.preventDefault();
$('#approveDialog').modal( 'hide' );
});
Upvotes: 9
Reputation: 3195
V3 you can try
success: function(data) {
// close modal
$( '#media_delete_confirmation' ).modal( 'hide' ).data( 'bs.modal', null );
// event after hidden
$('#media_delete_confirmation').on('hidden', function(){
$(this).data('modal', null); // destroys modal
});
}
Version 2
$( '#media_delete_confirmation' ).remove();
$( '.modal-backdrop' ).remove(); // removes the overlay
Upvotes: 0
Reputation: 3516
No need to hide model using javascript, you can simply use data-dismiss="modal" in the button tag attribute as follows.
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Keep</button>
<button type="button" class="btn btn-default" id="modal_delete" data-dismiss="modal">Delete</button>
</div>
Upvotes: 5