Nicolai VdS Nicolai VdS - 3 months ago 30
jQuery Question

Reset Form on Boostrap modal close event

So i have a data table that you can select a row and it gets the data from the table and puts it into a form thats in a modal all of that works but when i close the modal i wanna reset the form.

$('.modal').on('hide.bs.modal', function () {
// reset form
$('#user_form').trigger('reset');
});


but when i close the modal the form isnt reset.

demo - http://codepen.io/anon/pen/VjggYo

Answer

I think you do not need shown.bs.modal event to show data in modal.

Pleas try after removing this event.

$('.modal').on('shown.bs.modal', function () { }

And edit this :

$(this).find('input').each(function (index) {

To this:

$('.modal').find('input').each(function (index) {
Comments