Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activeadmin and Formtastic: form not responding to :size

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.

like image 941
Mark Tuttle Avatar asked Jan 12 '12 21:01

Mark Tuttle


2 Answers

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.

like image 56
Siwei Avatar answered Nov 12 '22 14:11

Siwei


i had the same problem. i wanted a nested form for edit with custom text field size.this worked for me.

    form do |f|
      f.inputs "Header" do
        cf.input :name, :input_html => { :class => 'some_style', :rows => 2, :style => 'width:50%'}
      end
      f.actions
    end

so basically u have to create your own class or just work with the :style.

For nested form u can use this code

    form do |f|
      f.inputs "Header" do
        f.has_many :name,:allow_destroy => true,:new_record => true do |cf|
          cf.input :first_name, :input_html => { :class => 'some_style', :rows => 2, :style => 'width:50%'}
        end
      end
      f.actions
    end
like image 5
user3619170 Avatar answered Nov 12 '22 14:11

user3619170