Search code examples
bootstrap-4bootstrap-selectbootstrap-selectpicker

Bootstrap-select jQuery plugin with Bootstrap 4


I'm new to Bootstrap and try to use Bootstrap-Select with Bootstrap 4 (could get it to work with Bootstrap 3) https://developer.snapappointments.com/bootstrap-select/

However, I'm confused with the different components which Bootstrap and the select needs. Sometimes the select does not open, sometimes the select opens but there's no search. I guess the components which are needed are wrong, but I dont have the experience to see what's wrong.

Would be great if somebody can help, thanks already ^^

<html>
<head>
    <meta charset="utf-8">
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

    <!-- Own CSS -->
    <link rel="stylesheet" type="text/css" href="templates/style.css" media="screen" />
</head>

<body>
    <select class="selectpicker" data-live-search="true">
        <option disabled="disabled" selected>- Select -</option>
        <optgroup label="Main Options">
            <option value="all">All Models</option>
            <option value="final">Final Models</option>
            <option value="prepared">Prepared Models</option>
        </optgroup>
    </select>

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/bootstrap-select.js"></script>
</body>
</html>


Solution

  • If you are using bootstrap 4 you need to use bootstrap-select v1.13.0+

    Bootstrap 4 only works with bootstrap-select v1.13.0+. By default, bootstrap-select automatically detects the version of Bootstrap being used. However, there are some instances where the version detection won't work. See the documentation for more information.

    <html>
    <head>
        <meta charset="utf-8">
        <!-- Bootstrap -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">
    
        <!-- Own CSS -->
        <!-- <link rel="stylesheet" type="text/css" href="templates/style.css" media="screen" /> -->
    </head>
    
    <body>
        <select class="selectpicker">
            <option disabled="disabled" selected>- Select -</option>
            <optgroup label="Main Options">
                <option value="all">All Models</option>
                <option value="final">Final Models</option>
                <option value="prepared">Prepared Models</option>
            </optgroup>
        </select>
    
        <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>
    </body>
    </html>