Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change size and maxlength allowed for a field in simple_form

How can I change the size and max allowed characters for a field using Simple Forms. I've tried following but does not work:

<%= f.input :lastname, :size => 40, :max => 4 %>

I know there is a default_input_size in initializers/simple_form.rb however, I don't want to change the size globally but just on few fields.

How would I do this?

like image 892
Omnipresent Avatar asked Mar 17 '11 16:03

Omnipresent


4 Answers

<%= f.input :lastname, input_html: { maxlength: 15, size: 40} %>
like image 165
Omnipresent Avatar answered Nov 04 '22 18:11

Omnipresent


try to use <%= f.input :lastname, :input_html => {:size => 40, :maxlength => 4} %>

like image 6
Sergey Kishenin Avatar answered Nov 04 '22 17:11

Sergey Kishenin


Or try to use CSS <%= f.input :lastname, :input_html => {:style => 'width: 250px'} %>

like image 5
Leo Lukin Avatar answered Nov 04 '22 16:11

Leo Lukin


Adding size and maxlength in input_html had no effect for me. I am using "input_field" instead of "input". So the following worked:

<%= form.input_field :effective_from_date,
                     as: :string,
                     class: 'activate-datepicker',
                     maxlength: 11,
                     size: 11,
                     label: false %>
like image 2
Pranesha Bunsee Avatar answered Nov 04 '22 17:11

Pranesha Bunsee