0

I am asking selectpicker() to reset the select box to default or "no" value -- I have tried to use

$("#select_state").val('').selectpicker("refresh");

OR

$("#select_state").val('default').selectpicker("refresh"); 

Per This Stack Overflow Question and This Stack Overflow Question

In addition, I found in the plugin a function called deselectAll() -- So I tried

$("#select_state").selectpicker("deselectAll");

To no avail. Can someone direct me to the correct way to reset, or refresh the selectpicker -- As I think the plugin has been updated since the past questions I have been reading ...

My select looks like this --

<select id="select_state" title="State" data-live-search="true" data-style="btn-info" data-width="125px">
    <option value="AL">Alabama</option>
    <option value="AK">Alaska</option>
    <option value="AZ">Arizona</option>
    <option value="AR">Arkansas</option>
    <option value="CA">California</option>
    ...
</select>
<script>
    $('#select_state').selectpicker();
</script>

NOTE There are no errors on the console log -- Adn the reset function fires just fine, and is resetting all my other fields to nothing IE

$('#email').val('');
$('#phone').val('');
$('#firstname').val('');
$('#lastname').val('');
$('#address').val('');
$('#city').val('');
$("#select_state").val('default').selectpicker("refresh");
$('#zip').val('');
Zak
  • 6,976
  • 2
  • 26
  • 48

1 Answers1

0

This is what I ended up doing -- I set the selectedIndex to 0. Then I refreshed it .. This is working for me.

var myselect = $("select#select_state");
myselect[0].selectedIndex = 0;
myselect.selectpicker("refresh");
Zak
  • 6,976
  • 2
  • 26
  • 48