Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display only the value in edit page in Active Admin

I have a edit form in Active Admin. I need some field as read only.

My current edit page is like

enter image description here

I need the page look like this

enter image description here

How can this be done. My code for the edit form page is like

    form :html => { :enctype => "multipart/form-data" } do |f|         f.inputs "Users" do         f.input :device, :label => 'Device', :as => :select, :collection => DEVICE, :include_blank => false         f.input :current_address, :label => 'Current Address', :as => :string       end     end 

Please help.

like image 613
Amal Kumar S Avatar asked Oct 03 '12 07:10

Amal Kumar S


2 Answers

As Alex said, set to disabled. You could then use css to get the visual you wanted, if you can live with the semantics of that.

The syntax was slightly different for me to get this to work.

in your admin form:

 f.input :finish_position, input_html: { disabled: true }  

in your CSS active_admin.css

input[disabled="disabled"], input[disabled] {   background-color: #F4F4F4;   border: 0px solid #F4F4F4 !important;   } 
like image 155
Will Avatar answered Oct 29 '22 01:10

Will


For a cleaner form definition within your ActiveAdmin.register{} block you may as well want to define a "readonly" input type to be used within active admin using formtastic:

Form block syntax is for activeadmin version 1.0.0.pre at 0becbef0918a.

# app/admin/inputs/readonly_input.rb  class ReadonlyInput < Formtastic::Inputs::StringInput   def to_html     input_wrapping do       label_html <<       template.content_tag('div', @object.send(method))     end   end end  # app/admin/your_model.rb  ActiveAdmin.register YourModel do   # ...    form do |f|     # ...      input :current_address, as: :readonly      # ...   end   end 
like image 32
David Avatar answered Oct 29 '22 01:10

David