【问题标题】:Activeadmin and Formtastic: form not responding to :sizeActiveadmin 和 Formtastic:表单没有响应 :size
【发布时间】:2012-01-12 21:48:47
【问题描述】:

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

我可以这样做:

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 文档引用了该文档。

【问题讨论】:

    标签: ruby-on-rails-3 formtastic activeadmin


    【解决方案1】:

    我不确定您的问题是否已解决。

    但是根据 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

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

    【讨论】:

    • 对我来说这行不通。行和类确实到达了文本区域,但什么也不做。我正在使用 Foundation Zurb。
    • 它也不适用于我的情况。我正在使用带有部分的 activeadmin 来生成表单
    • 活跃的管理员是邪恶的......让我们忘记它...... ^_^
    • ActiveAdmin 适用于非常简单的项目,因为不适用于需要大量自定义的大型项目。如此多的重新学习以及依赖于他们糟糕的文档使得使用起来非常令人沮丧。
    【解决方案2】:

    我有同样的问题。我想要一个用于编辑自定义文本字段大小的嵌套表单。这对我有用。

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

    所以基本上你必须创建自己的类或者只使用 :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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-01
      • 1970-01-01
      相关资源
      最近更新 更多