簡體   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