Neela
Neela

Reputation: 41

How to Refresh the Bootstrap modal fields after modal close

I have a Bootstrap modal with dynamic input fields and i need to empty all the field values after closing the modal.(i.e)i need to refresh the modal once it closed. I have tried clear(); and

$('body').on('hidden.bs.modal', '.modal', function () {
   $(this).removeData('bs.modal');
});

but not working for me.can you please suggest a working solution for this. Thanks in advance..

Upvotes: 3

Views: 759

Answers (1)

Jack Bashford
Jack Bashford

Reputation: 44087

Just iterate through each input in the modal and clear its value:

$('body').on('hidden.bs.modal', '.modal', function () {
    $(this).removeData('bs.modal');
    $(this).find("input").each(function(input) {
        input.val("");
    })(
});

Hopefully this helps!

Upvotes: 1

Related Questions