bootstrap select not showing items

RoshanaSheri picture RoshanaSheri · Aug 14, 2017 · Viewed 11k times · Source

I am trying to use bootstrap-select in my python flask web page. Following is the code I currently have.

   <head>

    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css')}}" >
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-responsive.min.css')}}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/font-awesome.min.css')}}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css')}}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/sl-slide.css')}}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-select.min.css')}}">

    <script src="{{ url_for('static', filename='js/jquery-3.2.1.min.js')}}" ></script>
    <script src="{{ url_for('static', filename='js/bootstrap.min.js')}}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap-dropdown.js')}}" ></script>
    <script src="{{ url_for('static', filename='js/bootstrap-select.js')}}" ></script>


    </head>
    <body>
    <section id="about-us" class="container main">
        <div class="row-fluid">
            <div class="span8" >
                <div class="blog">

                  <div class="blog-item well">
                    <a href="#"><h2>Heading2</h2></a>
                    <select class="selectpicker" id="select_county" data-live-search="true" data-style="btn-primary">
                      <option>County1</option>
                      <option>County2</option>
                    </select>

                    <select class="selectpicker" id="select_event" data-live-search="true" data-style="btn-primary">
                      <option>event1</option>
                      <option>event2</option>
                    </select>

                    <input type="submit" class="btn btn-info" value="Submit Button">


                    </div>

        </div>
    </div>
</div>
      <script type="text/javascript">
        $(document).ready(function(){
        $('.selectpicker').selectpicker('refresh');
       });
    </script>

</body>

Although data-live-search of select works, select is not showing any of the items other than the selected one.

enter image description here

I even refresh in $(document).ready(). What am I doing wrong?

Answer

amit wadhwani picture amit wadhwani · Aug 14, 2017

Below HTML is working fine, SECTION end/closing is missing in your html, Kindly remove script of document.ready as well. Refer below html.

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/bootstrap-select.min.js"></script>



</head>
<body>
    <section id="about-us" class="container main">
        <div class="row-fluid">
            <div class="span8" >
                <div class="blog">

                  <div class="blog-item well">
                    <a href="#"><h2>Heading2</h2></a>
                    <select class="selectpicker" id="select_county" data-live-search="true" data-style="btn-primary">
                      <option>County1</option>
                      <option>County2</option>
                    </select>

                    <select class="selectpicker" id="select_event" data-live-search="true" data-style="btn-primary">
                      <option>event1</option>
                      <option>event2</option>
                    </select>

                    <input type="submit" class="btn btn-info" value="Submit Button">


                    </div>

        </div>
    </div>
</div>
      </section>

</body>
</html>