How to reset bootstrap modal to its original contents on close?
You can make use of the Bootstrap's Modal Events. You should be concerned about these two:
hide.bs.modal
This event is fired immediately when the hide instance method has been called.hidden.bs.modal
This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).
So, you can do this:
$(function () {
// Delegating to `document` just in case.
$(document).on("hidden.bs.modal", "#myModalID", function () {
$(this).find("#info").html(""); // Just clear the contents.
$(this).find("#info").remove(); // Remove from DOM.
});
});
Update
Seeing your code, you might need to use this:
$(function () {
// Delegating to `document` just in case.
$(document).on("hidden.bs.modal", "#myModalID", function () {
$(this).find(".alert-danger").remove(); // Remove from DOM.
});
});
Reset modal window when closed
You can use this on click of the close button of your popup
this function will scroll viewport of the popup div to top when clicked
jQuery(document).on('click','.vc_general',function(){
var myDiv = document.getElementById('myNav');
myDiv.scrollTop = 0;
});
".vc_general" is one of the class in your close button. You can add an extra class if you think it will affect the other functionality.
Bootstrap modal does not update content and reset form in adminlte
It's obvious that your modal content remain on each time you open and close your modal, You should clear your modal content with the following code:
$(document).on('hidden.bs.modal', '.modal', function (e) { $(this).find(".modal-content").empty(); $(this).removeData('bs.modal');});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<button href="/edit/id" data-target="#new" data-toggle="modal" type="button" class="btn btn-success">Edit</button><div class="modal fade" id="new" tabindex="-1" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-body"> <img src="/image/loading.gif" class="loading"/> <span>Lodaing . . .</span> </div> </div> </div></div>
How clear bootstrap modal on hide
this is the easiest fix:
$('#myModal').on('hidden.bs.modal', function () {
$(this).find("input,textarea,select").val('').end();
});
Related Topics
Regular Expression for Not Allowing Spaces in the Input Field
How to Convert File to Base64 in JavaScript
How to Wait for One Function to Finish Before Continuing
How to Display an Iframe on Button Click
How to Trigger Change of Option in Dropdown When Options Can Have Same Value
How to Extract the User Name from an Email Address Using JavaScript
Remove the Default Browser Header and Footer When Printing HTML
Removing Number from Notification Icon
Using JavaScript to Detect Whether the Url Exists Before Display in Iframe
Fetch() Unexpected End of Input
How to Convert Raw Mp3 Binary into Blob Url and Play It in Audio Tag
Change Button Color When Click on the Button
Jquery Validate Phone Number With With Regex
How to Pass Array Variable from View to Controller in Spring MVC