Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap-select didnt show on page load

I'm trying to make a simple Bootstrap-select show up. But it doesn't show up.

When looking on the debugger, I saw that the display is none on the following line:

select.bs-select-hidden, select.selectpicker {
    display: none !important;
}

The point is I never added this class to my select. and would love to not see it in the debugger style window. It's the cause I think.

Here is the simple code:

<div class="input-group input-group-sm">                    
    <select class="selectpicker" id="event-name-ecom">
              <option value="addToCart" selected>Add To Cart</option>
              <option value="checkout">Checkout</option>
              <option value="removeFromCart">Remove From Cart</option>
              <option value="review" >Review</option>
              <option value="payment" >Payment</option>
              <option value="confirmation" >Confirmation Page</option>
    </select>
    <p class="bg-danger" id="event-required-ecom" style="margin-right: 25px; display: none"></p>
</div>

Any idea?

like image 624
Many man Avatar asked Jan 22 '16 19:01

Many man


4 Answers

This is likely too late for the answer to be useful to the original poster. But in case anybody else has this issue, I was able to fix it by explicitly adding .selectpicker('render') to my code:

$(".selectpicker").selectpicker({
    "title": "Select Options"        
}).selectpicker("render");
like image 121
trubliphone Avatar answered Oct 08 '22 08:10

trubliphone


Even I faced a similar issue but couldn't find the reason for this behavior. Initializing the bootstrap select explicitly worked for me. Just do (".selectpicker").selectpicker(), after your dom is ready.

like image 45
jyothsna Avatar answered Oct 08 '22 09:10

jyothsna


Use $(".selectpicker").selectpicker("refresh"); after your DOM is loaded.

$(document).ready(function() {
    $(".selectpicker").selectpicker("refresh");
});
like image 26
Vindhya p Avatar answered Oct 08 '22 07:10

Vindhya p


This class is in the bootstrap-select.css file which you include to style the selectpicker control.

It looks like your control is not getting automatically picked up by the selectpicker initialization code because you should have the hidden select, followed by a button and a div that contains all the selectpicker data. This can happen the control is added to the page after the initial load. When this happens, you should go ahead an run this javascript to initialize the selectpicker:

$('.selectpicker').selectpicker();
like image 42
Rachel Martin Avatar answered Oct 08 '22 08:10

Rachel Martin