3

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..

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
Neela
  • 41
  • 3
  • You'll have to get every `` and clear their values. [Here's](https://stackoverflow.com/questions/21151044/how-to-clear-all-input-fields-in-bootstrap-modal-when-clicking-data-dismiss-butt) a start – trinaldi Dec 12 '18 at 08:40
  • Thanks Tico , It's working for me... – Neela Dec 12 '18 at 12:52

1 Answers1

1

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!

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79