I have an array of Bootstrap Selectpickers to filter results from a database. I need a way to reset all selectpickers to "Nothing Selected", this is my code:
HTML
<div class="row"> <div class="col-md-3"> <label>By Group</label> <select id="groups" name="group" class="form-control selectpicker" multiple></select> </div> <div class="col-md-3"> etc... </div> </div>
Js
ajax_fetch('build_group_options', {groupno:groupno}).done(function(html) { //var html is a list of options in html format $('#groups').html(html).find('option[value=""]').remove(); //refresh the selectpicker to make sure options are registered in the picker $('.selectpicker').selectpicker('refresh'); });
Try reset all collectors:
$('#reset_filters').click(function() { $('.selectpicker').selectpicker('deselectAll'); $('.selectpicker').selectpicker('render'); $('.selectpicker').selectpicker('refresh'); $(this).closest('form').find('.selectpicker').each(function() { $(this).selectpicker('render'); }); });
As you can see, I tried all the reset functions, but to no avail, so I obviously did the wrong logic.
source share