Adding Search Functionality In Select Options Using Bootstrap


Answer :

To get a search functionality you must set the data-tokens attribute for each options. Here is your code after adding it. Let me know if you need additional help.

$(function() {   $('.selectpicker').selectpicker(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css" rel="stylesheet" />     <div class="container">    <div class="row">     <div class="col-xs-12">       <div class="box">         <!-- /.box-header -->         <div class="box-body">           <form>             <div class="form-group row">               <label for="" class="col-sm-2 form-control-label">Country</label>               <div class="col-sm-10">                 <select class="form-control selectpicker" id="select-country" data-live-search="true">                 <option data-tokens="china">China</option>   <option data-tokens="malayasia">Malayasia</option>   <option data-tokens="singapore">Singapore</option>                 </select>                </div>             </div>           </form>         </div>         <!-- /.box-body -->       </div>       <!-- /.box -->     </div>     <!-- /.col -->   </div>   <!-- /.row --> </div> <!-- /.container -->


    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">     <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/css/bootstrap-select.min.css" />  <select class="selectpicker" data-show-subtext="true" data-live-search="true"> <option data-tokens="name">name</option> <option data-tokens="family">family</option> </select>   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>   <script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/js/bootstrap-select.min.js"></script>


Multi Selection Form and searchable

$(function() { 	$('.selectpicker').selectpicker(); });
<!DOCTYPE html> <html> <head> 	<title></title> 	<script type="text/javascript" src="js/script.js"></script> 	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 	<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> 	<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script> 	<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css" rel="stylesheet" /> 	<script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"type="text/javascript"></script> 	<link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"rel="stylesheet" type="text/css" /> 	<script> 		$(function () { 			$('#lstFruits').multiselect({ 				includeSelectAllOption: true 			}); 			$('#btnSelected').click(function () { 				var selected = $("#lstFruits option:selected"); 				var message = ""; 				selected.each(function () { 					message += $(this).text() + " " + $(this).val() + "\n"; 				}); 			}); 		}); 	</script> </head> <body> <div class="container"> 	<div class="row"> 		<div class="col-xs-12"> 			<div class="box"> 				<div class="box-body"> 					<form action="#" method="POST"> 						<div class="form-group row"> 							<div class="col-sm-10"> 								<select class="form-control selectpicker" id="select-country lstFruits" multiple="multiple" data-live-search="true"> 									<option data-tokens="china">China</option> 									<option data-tokens="malayasia">Malayasia</option> 									<option data-tokens="singapore">Singapore</option> 								</select> 							</div> 						</div> 					</form> 				</div> 			</div> 		</div> 	</div> </div> </body> </html>


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable