16

I've tried

  #Default size for text inputs.  
  config.default_input_size = 10

from config/initializers/simple_form.rb

I've also tried <%= f.input :message, :input_html => {:size => 10} %>

But neither of these change a single thing about how my text fields appear.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
Linoux
  • 181
  • 1
  • 1
  • 3

8 Answers8

45

You need to do this

<%= f.input :message, :input_html => {:rows => 10} %>

Html text area tag attributes has two attributes namely rows and cols which lets you specify the no of rows and columns(i.e. width) of your text area. If this is not working then open the console and see if your css is overriding the height.

Super Engineer
  • 1,966
  • 1
  • 13
  • 21
  • I tried `<%= f.input :message, :input_html => {:cols => 20} %>` for a few values of the 'width' but it did not change. I looked at the source code and it seems that my field is wrapped by a `
    `. Any suggestions for how to change the default styling?
    – echo May 13 '15 at 23:23
16

Passing :input_html options override default values. You must check attributes values for css classes that can modify their behavior.

<%= f.input : message, :as => :text, :input_html => { 'rows' => 10} %>
aUXcoder
  • 1,048
  • 1
  • 20
  • 32
9

I managed to do this by adding :as => :text to the input field attributes and then adding style & rows to the input html:

<%= f.input :message, label: "Message: ", :as => :text, input_html: { :style=> 'width: 100%;', :rows => 4} %>

For me it was the :as => :text that got the "rows" attribute to work, and the 100% width made it fluid rather than fixed-width.

K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
rubynewbie14
  • 109
  • 1
  • 5
3

if you want to change "height", you need to modify css attribute:

<%= f.input :message, input_html: {style: 'height:10px;'} %>
Alper Karapınar
  • 2,694
  • 1
  • 25
  • 36
2

Old question, I know. This is what worked for me with SimpleForm 3.2.0 and Rails 4.2.3:

<%= f.input_field :field_name, as: :text, class: "my-custom-class", rows: 5 %>
dinjas
  • 2,115
  • 18
  • 23
1

You can do

<%= f.input :message, :size => "10x10" %>

for height and width.

It might work for text field but definitely works for text_area. You probably would want to use text_area for a message anyway.

roryhughes
  • 632
  • 5
  • 5
0

Try Firebug or Code Inspector from Google Chrome to inspect the text_field element, see the exactly class name and change it directly in your stylesheet file.

Kleber S.
  • 8,110
  • 6
  • 43
  • 69
0

I just had the same issue on Rails 5.1 and Bootstrap4. I did the following:

<%= f.input :bio, input_html: {style: 'height:200px !important;'} %>

and it works.

Rene Chan
  • 864
  • 1
  • 11
  • 25