text area with simple form

9,214 views
Skip to first unread message

zima

unread,
Dec 20, 2011, 11:12:29 AM12/20/11
to SimpleForm
Hello,

I am having a problem creating a text area in my Simple Form. In the
example (http://simple-form-bootstrap.herokuapp.com/articles/new) the
code just uses f.input and class "Span12" but the html generated from
it somehow has a text area tag inside of it. When I try to do the
same, i just get an extra long single line text input. What am I
doing wrong? What would be the right Rails code for textarea?

Thanks!

Natascha

Carlos Antonio da Silva

unread,
Dec 20, 2011, 11:15:18 AM12/20/11
to plataformate...@googlegroups.com
The input automatically detects the column type :text to generate a textarea. You can force it by giving :as => :text to the f.ínput call:

    f.input :description, :as => :text
--
At.
Carlos Antonio

Natalya Furmanova

unread,
Dec 20, 2011, 11:19:33 AM12/20/11
to plataformate...@googlegroups.com
Thanks!! It worked. Somehow I could not find this in the documentation..  There option :as is mentioned, but the possible values are not. 

Carlos Antonio da Silva

unread,
Dec 20, 2011, 11:39:26 AM12/20/11
to plataformate...@googlegroups.com
No problem :).

Actually I copied my f.input :description example from the README :D, as follows: 

SimpleForm also lets you overwrite the default input type it creates:
  <%= simple_form_for @user do |f| %>
    <%= f.input :username %>
    <%= f.input :password %>
    <%= f.input :description, :as => :text %>
    <%= f.input :accepts,     :as => :radio %>
    <%= f.button :submit %>
  <% end %>

And you can look at the "Mappings/Inputs available" section, which shows the current mappings (that you can use with the :as option), the input helper they are related to, and the automatic lookup based on the column type in your database. For instance, you have the text mapping, which maps to text area, and is created automatically when the column is type text.

Hope that helps :)
--
At.
Carlos Antonio

Natalya Furmanova

unread,
Dec 20, 2011, 11:47:04 AM12/20/11
to plataformate...@googlegroups.com
Thanks again. Now i see the examples.  One more little additional question: is there a way to control such things as the height or width of text area via options (well, width can be controlled via assigning one of the bootstrap classes, but height I did not find at all how..)? 

Carlos Antonio da Silva

unread,
Dec 20, 2011, 1:22:23 PM12/20/11
to plataformate...@googlegroups.com
You can do it with html attributes in the textarea, like this:

  f.input :description, :as => :text, :input_html => { :cols => 50, :rows => 5 }
--
At.
Carlos Antonio

Natalya Furmanova

unread,
Dec 21, 2011, 6:41:21 AM12/21/11
to plataformate...@googlegroups.com
Thanks, this all worked.. However, I am not sure if the actual bootstrap integration works. My form stays inline no matter what. I would like to make it stacked - and according to all the code, it should be something like that - 

<%= simple_form_for([:backend, shop_product], :wrapper => "stacked",  ) do |f| %>
  
  <%= f.input :name, :label => 'Titel', :input_html => { :class => "span6" } %>
  <%= f.input :description, :as => :text, :input_html => { :rows => 8 , :class => "span6"},:label => 'Beschreibung' %> 
   <%= f.input :image, :as=> :file, :label => 'Bild', :accept => 'image/*'  %>
   
   <%= f.input :price, :label => 'Preis' %>
   <%= f.input :vat, :label => 'Mwst.' %>
   <%= f.input :sizes, :label => 'Grössen' %>
   <%= f.input :colors, :label => 'Farben' %>
   <%= f.input :position, :label => 'Position' %>

  <fieldset class="options">
    <%= f.button :submit, 'Produkt speichern' , :input_html => { :class => "primary"} %> oder <%= link_to 'zurück zur Übersicht', backend_shop_products_path %>
  </fieldset>
<% end %>

. But the form stays inline-style. My config file was taken directly from the git repository of the authors (https://github.com/rafaelfranca/simple_form-bootstrap/blob/master/config/initializers/simple_form.rb) , and i am using simple form v 2.0 now.  Is there something with the wrappers? Or am I doing something wrong? 

Thanks again for all the responses.

Rafael Mendonça França

unread,
Dec 21, 2011, 9:09:08 AM12/21/11
to plataformate...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages