问题
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?
回答1:
<%= f.input :lastname, input_html: { maxlength: 15, size: 40} %>
回答2:
try to use <%= f.input :lastname, :input_html => {:size => 40, :maxlength => 4} %>
回答3:
Or try to use CSS <%= f.input :lastname, :input_html => {:style => 'width: 250px'} %>
回答4:
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 %>
回答5:
It's possible you declared your css for input widths set to 'auto'. Remove that declaration, and then customize.
来源:https://stackoverflow.com/questions/5342477/change-size-and-maxlength-allowed-for-a-field-in-simple-form