Activeadmin and Formtastic: form not responding to :size

Mark Tuttle picture Mark Tuttle · Jan 12, 2012 · Viewed 10.8k times · Source

I am trying to format a form and the text fields respond to some methods, and not others.

I can do things like:

f.input :name, :input_html => { :maxlength => 10 }
f.input :name, :input_html => { :disabled => true }

But if I try to do any of the following, they do not work:

f.input :name, :input_html => { :size => 10 }
f.input :name, :input_html => { :class => 'autogrow' }
f.input :name, :input_html => { :rows => 10, :cols => 10 }

When I try using :size, for instance, the generated html shows that size=10, but is not reflected in the actual form.

These were more or less pulled right from the Formtastic documentation on Github, which the Activeadmin documentation refers to.

Answer

Siwei picture Siwei · Mar 29, 2012

I am not sure if your question is solved or not.

However according to Formastic Official WIKI, your code should work:

Customize HTML attributes for any input using the :input_html option. Typically this is used to disable the input, change the size of a text field, change the rows in a textarea, or even to add a special class to an input to attach special behavior like autogrow textareas:

<%= semantic_form_for @post do |f| %>
  <%= f.inputs do %>
    <%= f.input :title,      :input_html => { :size => 10 } %>
    <%= f.input :body,       :input_html => { :class => 'autogrow', :rows => 10, :cols => 20, :maxlength => 10  } %>
    <%= f.input :created_at, :input_html => { :disabled => true } %>
    <%= f.input :updated_at, :input_html => { :readonly => true } %>
  <% end %>
  <%= f.actions %>
<% end %>

https://github.com/justinfrench/formtastic

if your code doesn't work , please check out the error logs, or put more debug info to your erb file, to see if you r rails is running under production mode.