Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple row text input with simple_form

I have this form:

<%= simple_form_for @article do |m| %>
  <%= m.simple_fields_for :article_comment do |p| %>

    <%= p.error_notification %>

    <%= p.input :article_id, as: :hidden, input_html: {value: @article.id} %>
      <div class="form-inputs">
        <div class="row">
          <div class="col-md-2 col-md-offset-1">
            <%= p.label 'What do you think?', :class => 'indexsubtext' %>
          </div>
          <div class="col-md-9">
            <%= p.input :comment, label: false, autofocus: true, :input_html => {:style=> 'width: 100%', :rows => 5, class: 'response-project'} %>
          </div>

I want the input box to show 5 rows, but it only shows 1. How do I force it to provide 5?

like image 767
Mel Avatar asked Oct 25 '15 04:10

Mel


1 Answers

By default, simple_form will choose the element based on the type in your database. If comment is of type string (rather than text), it will use an input field, which does not have a rows attribute.

Try adding an as: :text option. This will force the element to a textarea:

<%= p.input :comment, label: false, as: :text, autofocus: true, :input_html => {:style => 'width: 100%', :rows => 5, class: 'response-project'} %>

This may solve your problem as it did for this guy.

like image 189
K M Rakibul Islam Avatar answered Sep 22 '22 17:09

K M Rakibul Islam