Activeadmin 和 Formtastic:表单不响应:size

2023-12-28

我正在尝试格式化表单,文本字段响应某些方法,而不响应其他方法。

我可以做这样的事情:

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

但如果我尝试执行以下任何操作,它们都不起作用:

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

例如,当我尝试使用 :size 时,生成的 html 显示 size=10,但未反映在实际表单中。

这些或多或少是直接从 Github 上的 Formtastic 文档中提取的,Activeadmin 文档也引用了该文档。


我不确定你的问题是否得到解决。

然而根据 Formastic 官方 WIKI,你的代码应该可以工作:

使用 :input_html 选项自定义任何输入的 HTML 属性。 通常这用于禁用输入、更改文本大小 字段、更改文本区域中的行,甚至添加特殊类 到输入以附加特殊行为,例如自动增长文本区域:

<%= 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 https://github.com/justinfrench/formtastic

如果您的代码不起作用,请检查错误日志,或将更多调试信息放入您的 erb 文件中,以查看您的 Rails 是否在生产模式下运行。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Activeadmin 和 Formtastic:表单不响应:size 的相关文章

随机推荐