对于特定的情况,我希望将表单呈现为(用于原地编辑)的一部分。在formtastic中是否有一种方法可以禁用由.inputs / .buttons生成的布局?而不是
有没有内置的方法或任何解决这个问题的方案?
。
<fieldset> <ol> <li>
i would like simply to wrap the fields in the
<td>
有没有内置的方法或任何解决这个问题的方案?
。
<fieldset> <ol> <li>
i would like simply to wrap the fields in the
<td>
目前 Formtastic 没有内置的方法来更改标记语言。要么使用 CSS 调整现有的标记钩子,要么放弃使用 Formtastic 并编写自己的方式(就像我们以前做的那样)。
config/initializers/formtastic_foundation.rb:
# change required fields advice tag (abbr -> span)
Formtastic::FormBuilder.required_string =
proc { Formtastic::Util.html_safe(%{<span title="#{Formtastic::I18n.t(:required)}">*</span>}) }
module Formtastic
module Helpers
# change field wrapper (ol -> div)
module FieldsetWrapper
protected
def field_set_and_list_wrapping(*args, &block) #:nodoc:
contents = args.last.is_a?(::Hash) ? '' : args.pop.flatten
html_options = args.extract_options!
if block_given?
contents = if template.respond_to?(:is_haml?) && template.is_haml?
template.capture_haml(&block)
else
template.capture(&block)
end
end
contents = contents.join if contents.respond_to?(:join)
legend = field_set_legend(html_options)
fieldset = template.content_tag(:fieldset,
Formtastic::Util.html_safe(legend) << template.content_tag(:div, Formtastic::Util.html_safe(contents)),
html_options.except(:builder, :parent, :name)
)
fieldset
end
end
end
module Inputs
module Base
# change input wrapper tag (li.default_clases -> div.large-12.columns inside div.row)
module Wrapping
def input_wrapping(&block)
def super_wrapper_html_options
{:class => 'row'}
end
new_class = [wrapper_html_options[:class], "large-12 columns"].compact.join(" ")
template.content_tag(:div,
template.content_tag(:div,
[template.capture(&block), error_html, hint_html].join("\n").html_safe,
wrapper_html_options.merge(:class => new_class)),
super_wrapper_html_options)
end
end
end
end
end
我使用这段代码将Formtastic 3与Foundation 5.4.5集成。
目前还不支持,但是你可以使用 forked formtastic 版本: https://github.com/linoj/formtastic
更多细节请参考: http://www.vaporbase.com/postings/Replaceable_render_engines_for_Formtastic
在 formtastic 论坛上看到说有可能会合并到原版中。
I wrapped my call to the formtastic bit (in my haml file) in a string and then subbed out the
= "#{f.input ...}".gsub('<li class=', '<fart class=').html_safe #remove the li to align this input with the other text in the table.
It's a might bit easier than re-writing the form without formtastic, and it worked perfectly.
Admittedly it's a not an ideal solution. For a one off though... I can live with it.