0

How would I go about implementing a search bar with a filter, just like the one mentioned here: bootstrap amazon style search bar enter image description here

All the ones I see on bootstraps page refers to drop down lists with redirects, not select lists:

This is what I have so far but it doesn't look that great and I am unsure if I am doing it correctly.

enter image description here

<div class="col-md-9 col-md-push-1 ">
    <h3 class="text-center">Manage Users</h3>
    <div class="container">
        <div class="row">
            <div class="col-xs-8 col-xs-offset-2">
                <div class="input-group">
                    <div class="input-group-btn search-panel">
                        <select class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <option>All</option>
                            <option>Username</option>
                            <option>Email</option>
                            <option>Student Code</option>
                        </select>
                    </div>

                    <input type="hidden" name="search_param" value="all" id="search_param">
                    <input type="text" class="form-control" name="x" placeholder="Search term...">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"></span></button>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>
Eitan K
  • 837
  • 1
  • 17
  • 39
  • Do you mean "Buttons with dropdowns" ? see it on bootstrap docs http://getbootstrap.com/components/#input-groups-buttons-dropdowns – Aziz Sep 17 '15 at 21:37
  • @Aziz what I want is slightly different. I want it to look the same but when I click the drop down I want to be able to select something to filter by (select list) not have it redirect – Eitan K Sep 18 '15 at 12:24

1 Answers1

3

Well, I believe you need to wrap the inputs in a form tag which is missing in your code. Also the select tag requires a name attribute and the options must have a value set.

The dropdown menu should work as expected and there is no need for the hidden input - just simply parse the value from the select tag.

HTML Code (ignore the bootstrap library links) - JSFiddle

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<div class="col-md-9 col-md-push-1">
    <h3 class="text-center">Manage Users</h3>
    <div class="container">
        <div class="row">
            <div class="col-xs-8 col-xs-offset-2">
                <form action="#" method="get" id="searchForm" class="input-group">
                    
                    <div class="input-group-btn search-panel">
                        <select name="search_param" id="search_param" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <option value="all">All</option>
                            <option value="username">Username</option>
                            <option value="email">Email</option>
                            <option value="studentcode">Student Code</option>
                        </select>
                    </div>
                    <input type="text" class="form-control" name="x" placeholder="Search term...">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="submit">
                           <span class="glyphicon glyphicon-search"></span>
                        </button>
                    </span>
                </form><!-- end form -->     
            </div><!-- end col-xs-8 -->       
        </div><!-- end row -->  
    </div><!-- end container -->    
</div><!-- end col-md-9 -->

If it doesn't work then it can be a javascript issue which refreshes the page every time you select an option...

Aziz
  • 7,685
  • 3
  • 31
  • 54