开发者

change size and maxlength allowed for a field in simple_form

开发者 https://www.devze.com 2023-02-17 23:55 出处:网络
How can I change the size and max allowed characters for a field using Simple Forms.I\'ve tried following but does not work:

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?


<%= f.input :lastname, input_html: { maxlength: 15, size: 40} %>


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


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


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 %>


It's possible you declared your css for input widths set to 'auto'. Remove that declaration, and then customize.

0

精彩评论

暂无评论...
验证码 换一张
取 消