1

Referred this links Link1 Link 2 but not able clear the data's.

I am using bootstrap modal window in my web application. When modal is closed (triggered hidden event to clear the data), previously entered data's are not cleared.

Here is the fiddle` what i tried.Even I tried with form reset but not get success.

$("#modal").on('hidden.bs.modal', function (e) {
        $('#modal_form')[0].reset();
        $("#modal").removeData('bs.modal');
    });
    $("#modal").click(function() {

        $("#modal").removeData('bs.modal');
        $("#modal").modal();
    });
Community
  • 1
  • 1
Vini
  • 967
  • 1
  • 15
  • 33

2 Answers2

1

You need to reset $("#myModal form")[0] instead of $("#myModal form")

$("#myModal").on('hidden.bs.modal', function (e) { 
            $("#myModal form")[0].reset();
            $("#myModal form").find('span[style="color:red;"]').text(''); //reset error spans

          });
Kld
  • 6,970
  • 3
  • 37
  • 50
  • Thank you very much for you answer, but the span text still shows. https://jsfiddle.net/bk4gj48k/13/ – Vini Jul 20 '16 at 13:43
1

If you give the form an ID, you can do the following in jQuery. You can also add a class to your error spans and reset all of them at the same time.

$("#myModal").on('hidden.bs.modal', function (e) {
    $("#form").trigger('reset');
    $("#myModal .error").html('');
});


<span style="color:red;" id="username_span" class="error"></span>
Khris Roberts
  • 335
  • 1
  • 11