javascript - How to reset bootstrap modal to its original contents on close? -


p.s not in javascript , know question has been asked solutions not apply problem ask question again.

i'm stuck problem , haven't find solution yet. wanted clear things happened modal after close.

my modal form modal, whenever click submit, codeigniter validation messages show use of ajax on <div style="font-size:10px;width:50%;" id="info"></div> . whenever close modal, validation messages stays when re-open it. should done in order clear out after closing modal?

this function called ajax:

public function addcomp () {   $this->load->library('form_validation');   $this->load->helper('security');   $this->form_validation->set_rules('comp_name','computer name','trim|required|callback_pc_exist');   $this->form_validation->set_rules('status','status','trim|required');   $this->form_validation->set_rules('location','location','trim|required');    if ($this->form_validation->run()) {      $this->load->model('asset_model');     $result=$this->asset_model->addpc();      if (!$result) {       echo mysqli_error($result);     } else {       echo "<div class='alert alert-success alert-dismissable'>       <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>       computer added!</div>";     }   }   echo validation_errors("<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>","</div>"); } 

this ajax called submission:

$(document).ready(function(){   $("#addpc").submit(function(){     var formdata=$("#addpc").serialize();     $.ajax({       url:"asset_management/addcomp",       type:"post",       data: formdata,       async: true,     }).done(function( formdata ) {       $('#info').html(formdata);       $("#addpc")[0].reset();       viewdata();     });     return false;   }); }); 

you can make use of bootstrap's modal events. should concerned these two:

  • hide.bs.modal event fired when hide instance method has been called.
  • hidden.bs.modal event fired when modal has finished being hidden user (will wait css transitions complete).

so, can this:

$(function () {   // delegating `document` in case.   $(document).on("hidden.bs.modal", "#mymodalid", function () {     $(this).find("#info").html(""); // clear contents.     $(this).find("#info").remove(); // remove dom.   }); }); 

update

seeing code, might need use this:

$(function () {   // delegating `document` in case.   $(document).on("hidden.bs.modal", "#mymodalid", function () {     $(this).find(".alert-danger").remove(); // remove dom.   }); }); 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -