4

ある特定のケースでは、フォームを(インプレース編集用の)の一部としてレンダリングしたいと思います。.inputs / .buttonsによって生成されたレイアウトを無効にする方法はありますか?代わりに

<fieldset> <ol> <li> 

単にフィールドをラップしたいのですが

<td>

この問題に対する組み込みの方法または解決策はありますか?

4

4 に答える 4

2

Formtasticには、マークアップを変更するための組み込みの方法は(まだ)ありません。CSSを使用して十分なマークアップフックを適切に調整するか、このフォームのFormtasticを捨て​​て、独自の方法でコーディングします(以前のように)。

于 2010-11-02T20:56:22.233 に答える
1

まだサポートされていませんが、フォークされたformtasticバージョンを使用できます: https ://github.com/linoj/formtastic

詳細については、 http ://www.vaporbase.com/postings/Replaceable_render_engines_for_Formtasticをご覧ください。

いつかオリジンにマージされるかもしれないという形のフォーラムを読んでください。

于 2011-06-06T15:33:42.993 に答える
1

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

このコードを使用して、Formtastic3をFoundation5.4.5と統合します

于 2014-12-02T17:54:30.353 に答える
-2

(hamlファイル内の)formtasticビットへの呼び出しを文字列でラップしてから、

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

フォームを作成せずにフォームを書き直すよりも少し簡単かもしれませんが、完璧に機能しました。

確かに、それは理想的な解決策ではありません。でも一回限り...私はそれと一緒に暮らすことができます。

于 2012-11-30T01:02:20.317 に答える