Is there a way to disable the default default formatting form?

In one specific case, I would like to present the form as part (for in-place editing). Is there a way in formtastic to disable a layout created using .inputs / .buttons? Instead of this

<fieldset> <ol> <li> 

I would like to just wrap the fields in

<td>

Is there a built-in way or any solution to this problem?

+3
source share
4 answers

There is no built-in way (yet) in Formtastic to change the margin. Either use CSS to set up abundant markup hooks in place, or cut out Formtastic for this form and encode your own path (as we used to).

+2

, , :

//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

+1

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. 

, formtastic, .

, . , ... .

-2

Source: https://habr.com/ru/post/1772445/


All Articles