javascript - How to reset a select box after hiding a modal? -


i have select box:

<select class="selectpicker" id="select_seleccionar_proyecto_id">     <option value="0">seleccione..</option>     <option value="1">tarea número 1</option>     <option value="2">tarea número 2</option>     <option value="3">tarea número 3</option>     <option value="4">tarea número 4</option>     <option value="5">tarea número 5</option>     <option value="6">tarea número 6</option> </select>    

the select box located in modal, , after close modal, select box remains last selected option last time.

i built method called after modal hidden nothing have tried seems reset select box:

limpiarmodaltarea: function(){      var self = this;      //my attempts:     /*      * $("select option[value='0']").attr("selected","selected");      * $("select_seleccionar_proyecto_id").val($("select option[value='0']").val());      * $("#target").val($("#select_seleccionar_proyecto_id option:first").val());      * $( "#select_seleccionar_proyecto_id option:first" ).val();       */ }, 

i put alert in limpiarmodaltarea , when closed modal, alert work.. know method called.

any suggestions?

modal image http://www.uppic.com/uploads/14302560911.jpg

edit:

i'm sorry, did not mention work different modules.

in module "a" have method contains button opens modal method , published:

this method contains html:

                    +                                            '<a href="#mymodal2" role="button" class="btn btn-success btn-sm" id ="btn_seleccionartarea_'+icontproyecto+'_id" data-toggle="modal"><strong>seleccionar una tarea</strong></a>'                     +    

this method contains publication:

publicarbotonseleccionartarea: function(iconttarea){      var self = this;      $("#btn_seleccionartarea_"+iconttarea+"_id").click(function(){     self.publishers("seleccionproyecto_seleccionartarea", iconttarea);     }); }, 

in module "b " subscribe method :

subscribers : function() {      var self = this;     self.sb.subscribe('seleccionproyecto_seleccionartarea', function(data) {     self.idtarea=data;     self.showmodal();     });     }, 

action buttons in modal:

cargaracciones: function(){      var self = this;     self.hideerror();     $('#btn_modal_seleccionartarea_cancelar_id').click(function(){      self.hidemodal();     self.hideerror();      });       $('#btn_modal_seleccionartarea_aceptar_id').click(function(){      var selecciontarea = $( "#select_seleccionar_proyecto_id option:selected" ).val();     if(selecciontarea!=0){     self.envionombretarea();     self.hidemodal();     }else{     self.showerror();      }       });     }, 

then start work on mentioned before ,so don´t have button on same module.

i need clean modal in module b

as charlietfl pointed out, simplest use

$('select').val('0'); 

to reset select element leaving first option element visible.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -