Saghir A. Khatri
Saghir A. Khatri

Reputation: 3128

bootstrap class not working with select

I am working on ruby on rails application and trying to reduce size of select. I have 'bootstrap gem' installed for my application. Here is the code

 <%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
     :include_blank => {:year => "Select year"}, :class=>"input-small" %>

as I noticed class values from this question Change width of select tag in Twitter Bootstrap. But seems like it is not working with this select. I have tried

<%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
    :include_blank => {:year => "Select year"}, :style=>"100px" %>

but nothing happened. Plz let me know what i am missing. Thanks

Upvotes: 0

Views: 376

Answers (4)

Monideep
Monideep

Reputation: 2810

Try this

<%= f.select(:fromyear, options_for_select((1995..Time.now.year).to_a.reverse), {:include_blank => 'Select year'}, { :class => 'input-small' }) %>

Or you can even include inline style inside a select tag with

<%= f.select(:fromyear, options_for_select((1995..Time.now.year).to_a.reverse), {:include_blank => 'Select year'}, { :class => 'input-small', :style => 'width:200px;', required: true }) %>

Upvotes: 0

Kirti Thorat
Kirti Thorat

Reputation: 53038

As per the syntax for f.select (in form_for):

f.select(method, choices = nil, options = {}, html_options = {}, &block)

Right now you are passing include_blank and class as options parameter which is why the class is not applied. class must go inhtml_options.

All you need to do is separate out options and html_options.:

 <%= f.select :fromyear, (1995..Time.now.year).to_a.reverse, 
     {:include_blank => {:year => "Select year"}}, :class=>"input-small" %>
     ^                                          ^ 
   ## Added a curly bracket to separate out `include_blank` option and `class` option.

Upvotes: 2

Raghuveer
Raghuveer

Reputation: 2638

Did you try this way?

= a.input :country, :as => :select, :collection => country_code_localized_map, :include_blank => false, :input_html=>{:class => "reg-input"}

Or else you can add another %DIV.select_above_class above the select tag and apply styles via above class to select tag

.select_above_class select{
   // your css styles
}

Upvotes: 1

D.Fux
D.Fux

Reputation: 376

Maybe you forget to input the 'width' in the option :style ?

:style=>"width:100px"

Upvotes: 1

Related Questions