Open jrichview opened 4 years ago
This might be a good one to integrate (especially to more easily support an array of indices for a multiple select). For a single select, something like this should work:
var $select = $("#select-id");
$select[0].selectedIndex = 4;
$select.selectpicker("refresh");
I find the following to be more JQUERY-friendly way to write it, but it's the same:
$('#' + ddlDuration).prop('selectedIndex', 0).selectpicker('refresh');
It sure would be nice if the selectpicker were able to hook the onchange of the hidden dropdown and know it needs to refresh auto-magically.
The documentation for the selectpicker('val') function does not talk about setting the selected index rather than selected value. My first thought when reading it was "can I pass an number/index instead of the text value?".
As you know, sometimes you need to do one, and other times the other. It would be really helpful if there was some mention of setting the selected index programmatically in that part of the documentation even if you're just giving an example of setting it as you would with any plain-jane dropdown.