How do I reload only in modal window? [closed]

1

I'm using modal Bootstrap and wanted to close and open the new modal information to be reset.

I have form within modal, containing select , textarea , input . But when opening the modal of the bottom line, if the user modified something in the first modal it appears in the modal of the line below.  I used the command below

$('#myModalpv').on('hidden.bs.modal', function () {
    location.reload();
})

But it does on the whole page, I would like it to reload, back up the modal in the initial state, when the user opens the next modal.

I also used the code below:

  $('#myModalpv').on('hidden.bs.modal', function () {
      $('#form2 input select').each(function() {
          $(this).val('');
      });
  });

Cleared the information but did not return to the initial state of my modal.

    
asked by anonymous 17.05.2017 / 04:54

3 answers

1

Do you want to clear all modal content?

If it is, you can remove the contents of the body.

For example:

$('#myModalpv').on('hidden.bs.modal', function () {
 $(".modal-body").html("");
})
    
17.05.2017 / 12:28
0

My two cents:

  • 1) You should have a function that creates the modal from scratch according to your need. This way, whenever you need to, you can build a new one from scratch, with the initial state;

  • 2) I think $('#form2 input select') selects all selects within inputs within form 2. Maybe what you really want is something like:

$("#form2").find("input, select").each(function () { // Atenção à vírgula
    //aqui você limpa.
});
    
17.05.2017 / 15:18
0

If it's form fields, you can simply reset

$('form').reset();

You can use it as well ...

   $('form').each(function(){
  $("#select").val($("#select option:first").val());

});

link

    
17.05.2017 / 15:19