Sha256: 634a8b1464df8dd63f2130db3ac1fd6c2655d7e751af651cade5b30b66e5dad8

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

module Para
  module FormHelper
    def para_form_for(resource, options = {}, &block)
      default_options = {
        as: :resource,
        wrapper: :horizontal_form,
        html: { class: '', data: { :'para-form' => true } }
      }

      options = default_options.deep_merge(options)

      options[:html][:class] = [
        options[:html][:class].presence,
        'form-horizontal form-group-separated'
      ].compact.join(' ')

      unless options.key?(:url)
        options[:url] = @component.relation_path(resource)
      end

      if options.fetch(:fixed_actions, true)
        default_options[:html][:class] << ' form-fixed-actions'
      end

      simple_form_for(resource, options) do |form|
        capture { block.call(form) }.tap do |content|
          # Append hidden field with type if resource is subclassable
          # to avoid bad class instantiation in create action
          if @component.subclassable? && resource.new_record?
            content << form.hidden_field(:type, value: resource.type)
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
para-0.6.9 app/helpers/para/form_helper.rb
para-0.6.8 app/helpers/para/form_helper.rb
para-0.6.7 app/helpers/para/form_helper.rb
para-0.6.3 app/helpers/para/form_helper.rb
para-0.6.2 app/helpers/para/form_helper.rb
para-0.5.4 app/helpers/para/form_helper.rb
para-0.5.3 app/helpers/para/form_helper.rb
para-0.5.1 app/helpers/para/form_helper.rb
para-0.5.0 app/helpers/para/form_helper.rb