How do I Reload only in the modal window?

Asked

Viewed 2,084 times

1

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

I have a form within the modal, containing select, textarea, input. But when opening the modal from the bottom line, if the user modified something in the first modal it appears in the modal from 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 you to do the Reload, turn 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.

  • Precisely what information?

  • 1

    Do you want to Reload or clear fields? And it’s only in the modal window?

  • Correct Jorge, I have a <form> inside the modal with input, textarea, select, but when I open the modal of the line below it still contains the information that was modified when opened the modal previously.

3 answers

1

You want to clear all modal content?

If so, you can remove the body content.

Ex:

$('#myModalpv').on('hidden.bs.modal', function () {
 $(".modal-body").html("");
})
  • Thank you, but that’s not what I needed, but I found it very interesting.

0

My two cents:

  • 1) You should have a function that creates the modal from scratch as needed. That way whenever you need you can assemble a new one from scratch, with the initial state;

  • 2) I think that $('#form2 input select') selects all the selects inside 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.
});

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.