flamant
flamant

Reputation: 783

Trying to use bootstrap-select for my dropdown

I develop a site with bootstrap and I am facing an issue with a select component. Here is the code

<tr>
    <td>    
        <div class="textAlignCenter">   
           <select  class="selectpicker" formControlName="maritalSituation">
                <option value="" selected>Situation maritale</option>
                <option value="MARIE">Marié</option>
                <option value="DIVORCE">Divorcé</option>
                <option value="CELIBATAIRE">Célibataire</option>
                <option value="VEUF">Veuf</option>
            </select>
        </div>  
    </td>
</tr>

I use bootstrap-select to design the dropdown (https://www.npmjs.com/package/bootstrap-select), but it does not appear. When I inspect Firebug, I have the following class

select.selectpicker {
    display: none !important;
}

So the select element is not visible. I don't understand, because I tried it with fiddle and it works (https://jsfiddle.net/flamant/3r6kucf8/4/)

The only class related select in my application is the following

select {
  @extend input;
}

and when I remove it nothing change

Upvotes: 2

Views: 3583

Answers (1)

focus.style
focus.style

Reputation: 6760

Maybe you forgot to add something? Like bootstrap-select JS and CSS, because it is not standard Bootstrap functions, but an additional library. Works fine. Look please.

$(function () {
    $('.selectpicker').selectpicker();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<!-- needs for bootstrap-select -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>

<!-- bootstrap -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>

<!-- bootstrap-select additional library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.17/css/bootstrap-select.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.17/js/bootstrap-select.min.js"></script>

<select  class="selectpicker" data-live-search="true">
  <option value="" selected>Situation Maritale</option>
  <option value="MARIE">Marié</option>
  <option value="DIVORCE">Divorcé</option>
  <option value="CELIBATAIRE">Célibataire</option>
  <option value="VEUF">Veuf</option>
</select>

Upvotes: 2

Related Questions