How can i reset a selectpicker after hide a modal?

(sorry my english)

Hey , well i have a select picker:

                    +                       
                    '<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>'         

this select box is in a modal, and when i close this modal, the select box is like the last time , example: i select "tarea numero 4", i close the modal and open the modal and "tarea numero 4" is selected. Well, i have a method that i call after hide the modal and when i open i need "seleccionar..", but nothing work..

¿what is the best option in jquery? thanks

HideModal: function(){
    var self = this;
    $('#modal_seleccionar_tarea_id').modal('hide');
    self.LimpiarModalTarea();
    },

LimpiarModalTarea: function(){
var self = this;

 $('#select_seleccionar_proyecto_id').val("0");},

PD : this work in other modal, but with textarea.

Upvotes: 0

Views: 5422

Answers (3)

Sebastian Abiel
Sebastian Abiel

Reputation: 33

If you are using bootstrap-select

$("selectorOfSelect").val('0').selectpicker('refresh');

Upvotes: 2

Theo
Theo

Reputation: 2042

i think you are looking for this $("#select_seleccionar_proyecto_id").prop('selectedIndex',0);

stackoverflow Set the selected index of a Dropdown using jQuery

Upvotes: 0

Norlihazmey Ghazali
Norlihazmey Ghazali

Reputation: 9060

Try change your jquery code

from

$('#select_seleccionar_proyecto_id').val("0");

into

$("#select_seleccionar_proyecto_id")[0].selectedIndex = 0;
               //<<--  or
$("#select_seleccionar_proyecto_id").get(0).selectedIndex = 0;

Normally, by using $('#select_seleccionar_proyecto_id').val("0"); also work, is that LimpiarModalTarea function work when called in hidemodal function?? If did't ensure those function work by putting an alert to ensure that.

Upvotes: 0

Related Questions