3

I'm trying to use this selectpicker for form selects and options, but can't get it to work.

I've added the following scripts and css as specified:

 <script type="text/javascript"> $('.selectpicker').selectpicker({ }); </script> <script src="/js/Bootstrap/Select/bootstrap-select.js"></script> 

html for the 1st greyed out select in the search bar:

<select class="selectpicker" id="searchType" name="searchtype" onchange="this.form.submit()"> <option value="All">All</option> <option value="Businesses">Businesses</option> <option value="Events">Events</option> <option value="News">News</option> <option value="Lifestyle">Lifestyle</option> </select> 

Any ideas appreciated.

3 Answers 3

7

Please be sure that you included all the required files or You may have to rearrange the code like :

<script src="/js/Bootstrap/Select/bootstrap-select.js"></script> <script type="text/javascript"> $('.selectpicker').selectpicker({ }); </script> 

You need to include the js first then call the the plugin. Check this fiddle, its working for me : http://jsfiddle.net/tejashsoni111/RUAS4/

Sign up to request clarification or add additional context in comments.

3 Comments

Its the bootstrap's default css applied on it, you need to overwrite or customize the css as per your requirement. For example, if you see in the fiddle, there is an option for style: 'btn-info', in this option you can add your own style class.
the blue color is coming up because the select pickers style has been set to style: 'btn-info',`, hence bootstrap css is adding the blue color to it thinking it as info button. just remove that,check here i have modified, jsfiddle.net/dreamweiver/RUAS4/1
@uname12: with this attitude you wont find an answer bro , your on your own now.
2

.selectpicker() is a function defined under bootstrap-select lib and not in core bootstrap library,hence you need to include that library as well

//silviomoreto.github.io/bootstrap-select/javascripts/bootstrap-select.js

//silviomoreto.github.io/bootstrap-select/stylesheets/bootstrap-select.css

HTML:

 <select class="selectpicker" id="searchType" name="searchtype" onchange="this.form.submit()"> <option value="All">All</option> <option value="Businesses">Businesses</option> <option value="Events">Events</option> <option value="News">News</option> <option value="Lifestyle">Lifestyle</option> </select> 

JQUERY CODE:

$('.selectpicker').selectpicker(); 

Here is a Live Demo of select picker function :

http://jsfiddle.net/dreamweiver/2a9xp/13/

Happy Coding :)

1 Comment

@uname12: if its still not working then check on console if there is any error also check if all the necessary libraries are loaded or not
0

In case anyone using Rails is experiencing a similar problem - the issue was arising from the existence of the precompiled assets for the AWS deployment that were lingering in my local environment.

Deleting YourRailsApp/public/assets solved the issue for me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.