Mar*_*tle 8 formtastic ruby-on-rails-3 activeadmin
我正在尝试格式化表单,文本字段响应某些方法,而不是其他方法.
我可以这样做:
f.input :name, :input_html => { :maxlength => 10 }
f.input :name, :input_html => { :disabled => true }
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试执行以下任何操作,它们就不起作用:
f.input :name, :input_html => { :size => 10 }
f.input :name, :input_html => { :class => 'autogrow' }
f.input :name, :input_html => { :rows => 10, :cols => 10 }
Run Code Online (Sandbox Code Playgroud)
例如,当我尝试使用:size时,生成的html显示size = 10,但不会反映在实际形式中.
这些或多或少是从Github上的Formtastic文档中提取的,Activeadmin文档引用了该文档.
Siw*_*申思维 12
我不确定你的问题是否得到解决.
但是根据Formastic Official WIKI,你的代码应该有效:
使用:input_html选项为任何输入自定义HTML属性.通常,这用于禁用输入,更改文本字段的大小,更改textarea中的行,甚至将特殊类添加到输入以附加特殊行为,如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 %>
Run Code Online (Sandbox Code Playgroud)
https://github.com/justinfrench/formtastic
如果您的代码不起作用,请查看错误日志,或将更多调试信息添加到您的erb文件中,以查看您是否在生产模式下运行.
我有同样的问题.我想要一个嵌套的表单用于编辑自定义文本字段大小.这对我有用.
form do |f|
f.inputs "Header" do
cf.input :name, :input_html => { :class => 'some_style', :rows => 2, :style => 'width:50%'}
end
f.actions
end
Run Code Online (Sandbox Code Playgroud)
所以基本上你必须创建自己的类或只使用:style.
对于嵌套表单,您可以使用此代码
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9686 次 |
| 最近记录: |