Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't change the height of a text field in simple_form

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.

like image 210
Linoux Avatar asked Nov 25 '12 23:11

Linoux


4 Answers

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.

like image 59
Super Engineer Avatar answered Oct 15 '22 09:10

Super Engineer


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} %>
like image 22
aUXcoder Avatar answered Oct 15 '22 09:10

aUXcoder


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.

like image 9
rubynewbie14 Avatar answered Oct 15 '22 08:10

rubynewbie14


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

<%= f.input :message, input_html: {style: 'height:10px;'} %>
like image 3
Alper Karapınar Avatar answered Oct 15 '22 09:10

Alper Karapınar