将非输入行插入到Formtasic表单中 [英] Insert a non-input row into a Formtasic form

查看:81
本文介绍了将非输入行插入到Formtasic表单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Rails 3.2(使用Active Admin)中使用Formtastic 2.1.1,并且我想在我的表单中插入没有输入字段的行。这可能吗?在Formtastic DSL中使用什么语法来实现这一目标?

I am using Formtastic 2.1.1 in Rails 3.2 (with Active Admin) and I want to insert a row into my form that does not have an input field present. Is this possible and what is the syntax in the Formtastic DSL to achieve this?

以下是示例:

form do |f|

    f.inputs "Model Info" do
      f.input :title
      f.input :published
      f.input :path
    end

end

我想做这样的事情:

form do |f|

    f.inputs "Model Info" do
      f.input :title
      f.input :published
      f.input :path
      f.div "This is some important text that people using this form need to know"
    end

end

以前有人用过Formtastic吗?

Has anyone done this with Formtastic before?

推荐答案

要在中插入任何自定义代码任何位置,您可以使用 f.form_buffers.last

To insert any custom code in any place, you may use f.form_buffers.last:

form do |f|
  f.form_buffers.last << "<p>Hello world!</p>".html_safe # The simple way

  ft = f.template # just a helper variable

  f.inputs "Foo" do
    f.input :title

    f.form_buffers.last << ft.content_tag(:li) do
      ft.content_tag(:p, "Hello again!") +
          ft.tag(:input, type: :hidden, name: "bar[]", value: "baz")
    end
    f.input :path
  end
end

请注意HTML结构。如果从 f.inputs 块调用此代码,则代码将放置在< ol> 元素内。在表单级别上,您位于< form> 元素内。

Just be careful about the HTML structure. If you call this from f.inputs block, your code will be placed inside an <ol> element. On the "form" level, you are inside a <form> element.

有点警告:与任何未记录的功能一样,此方法在任何新版本中都可能更改而不会发出警告。

A little warning: As with any "undocumented feature" this method may change without warning in any new release.

这篇关于将非输入行插入到Formtasic表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆