繁体   English   中英

有没有办法禁用默认的表格布局?

[英]Is there a way to disable default formtastic layout?

对于一个特定的情况,我想将表单呈现为一部分(用于就地编辑)。 有没有一种形式上的方法来禁用.inputs / .buttons生成的布局? 而是

<fieldset> <ol> <li> 

我只想将字段包装在

<td>

是否有内置方法或任何解决此问题的方法?

在Formtastic中,还没有内置的方式可以更改标记。 您可以使用CSS来调整适当的标记挂钩,也可以放弃Formtastic来编写此表单并以自己的方式编写代码(就像我们以前一样)。

在rails中,您可以覆盖定义用于渲染元素的标签的函数:

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集成在一起

尚不支持,但是您可以使用派生的formtastic版本: https : //github.com/linoj/formtastic

更多详细信息,请访问: http//www.vaporbase.com/postings/Replaceable_render_engines_for_Formtastic

在正式论坛上阅读,有一天它甚至可能合并为起源。

我将对格式化的位(在haml文件中)的调用包装在字符串中,然后消除了

= "#{f.input ...}".gsub('<li class=', '<fart class=').html_safe #remove the li to align this input with the other text in the table. 

这可能比不使用formstic重写表单要容易一些,并且效果很好。

诚然,这不是一个理想的解决方案。 对于一个关闭...我可以忍受。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM