Ama*_*r S 26 formtastic ruby-on-rails-3 activeadmin
我在Active Admin中有一个编辑表单.我需要一些字段作为只读.
我当前的编辑页面就像

我需要页面看起来像这样

如何才能做到这一点.我的编辑表单页面的代码就像
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
Run Code Online (Sandbox Code Playgroud)
请帮忙.
Wil*_*ill 42
正如亚历克斯所说,设置为禁用.然后,您可以使用css来获取您想要的视觉效果,如果您可以使用它的语义.
我的语法略有不同,让我的工作.
在您的管理表单中:
f.input :finish_position, input_html: { disabled: true }
Run Code Online (Sandbox Code Playgroud)
在你的CSS active_admin.css中
input[disabled="disabled"],
input[disabled] {
background-color: #F4F4F4;
border: 0px solid #F4F4F4 !important;
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*vid 13
为了在ActiveAdmin.register {}块中更清晰的表单定义,您可能还希望使用formtastic定义要在活动管理中使用的"只读"输入类型:
表单块语法适用于0becbef0918a的activeadmin版本1.0.0.pre.
# 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
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,并尝试使用:disabled它,但是它不能解决我的问题,因为我希望field在将值params发送到服务器时将其包含在对象中。当你标记form input的:input_html => {:disabled => true},它不包括在此字段的值params。因此,我改用:input_html => {:readonly => true}来解决我的两个问题:
editparams我希望这将有所帮助。
| 归档时间: |
|
| 查看次数: |
15185 次 |
| 最近记录: |