Pavel
Pavel

Reputation: 1974

Rails - simple form

I use simple_form gem in my Rails app. When I use code like this

= f.input_field :name, label: false, placeholder: 'Name'
= f.input_field :price, label: false, placeholder: 'Price'
= f.input_field :description, label: false, placeholder: 'Description'
= f.input_field :image, label: false, placeholder: 'Image'

I get HTML for input:

<input class="string required textform" id="item_name" label="false" maxlength="255" name="item[name]" placeholder="Имя" size="255" type="text">

As you can see size of input is 255 now. Actually it's much more than enough. How can specify the size of inputs?

Upvotes: 0

Views: 120

Answers (2)

amitamb
amitamb

Reputation: 1067

Following is from simple_form documentation here

It is also possible to pass any html attribute straight to the input, by using the :input_html option, for instance:

<%= simple_form_for @user do |f| %>
  <%= f.input :username, input_html: { class: 'special' } %>
  <%= f.input :password, input_html: { maxlength: 20 } %>
  <%= f.input :remember_me, input_html: { value: '1' } %>
  <%= f.button :submit %>
<% end %>

Upvotes: 2

vee
vee

Reputation: 38645

To set size of 100 for name input:

= f.input :name, label: false, placeholder: 'Name', input_html: { size: 100 }

Upvotes: 1

Related Questions