3

I am using bootstrap-modal.js v2.3.2

Whenever I close the model basically it toggles the modal, meaning previous data persists.

What I'd like is for:

  • Every time I close or hide the modal, it should destroy its data.
  • Every time I open the modal, it should create a new instance.

I tried something like :

$('#update-addresstype').on('hidden.bs.modal', function () {
    $(this).data('modal', null);
})

But it does not seems to be working.

henrywright
  • 10,070
  • 23
  • 89
  • 150
maaz
  • 3,534
  • 19
  • 61
  • 100
  • 1
    You want to kill data in a form or what..? – Mike Barwick Nov 26 '13 at 05:22
  • 1
    yes / i am showing the select box in modal dilog box, when i hide and repoen the previous selected data still present there i need to show a fresh select box – maaz Nov 26 '13 at 05:25

1 Answers1

1

If you're trying to "reset" a form, use jQuery .reset(), as below:

$('#update-addresstype').on('hidden.bs.modal', function () {
    $(this).data('modal', null);
    $('form')[0].reset();
});

Or to reset a <select />, try this (be sure to change the #select-id and value to match your corresponding HTML):

$('#update-addresstype').on('hidden.bs.modal', function () {

    $('#select-id option').removeAttr('selected');
    $('#select-id option[value="0"]').attr('selected',true);

    $(this).data('modal', null);
});
Mike Barwick
  • 6,288
  • 6
  • 51
  • 76