Sha256: b37bc990441eff6298f707b58360304fa3a1d35514d2a7dd7aa2cf98902cb4a5

Contents?: true

Size: 1.46 KB

Versions: 48

Compression:

Stored size: 1.46 KB

Contents

module Para
  module FormHelper
    def para_form_for(resource, options = {}, &block)
      default_options = {
        as: :resource,
        wrapper: :vertical_form,
        wrapper_mappings: Para::SimpleFormConfig.wrapper_mappings,
        track_attribute_mappings: true,
        html: {
          class: '',
          data: { :'para-form' => true },
          # Force multipart forms to allow forms with no file input on creation
          # to fetch nested fields with image inputs through the remote nested
          # form loading system. Without this option, rails does not create a
          # multipart form when there is no file input during the form creation.
          multipart: true
        }
      }

      options = default_options.deep_merge(options)

      options[:html][:class] = [
        options[:html][:class].presence,
        'form-vertical forms-outline'
      ].compact.join(' ')

      unless options.key?(:url)
        options[:url] = @component.relation_path(resource)
      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

          content << form.attributes_mappings_field_for(form)
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
para-0.8.13 app/helpers/para/form_helper.rb
para-0.8.12 app/helpers/para/form_helper.rb
para-0.8.11 app/helpers/para/form_helper.rb
para-0.8.10 app/helpers/para/form_helper.rb
para-0.8.9 app/helpers/para/form_helper.rb
para-0.8.8 app/helpers/para/form_helper.rb
para-0.8.7 app/helpers/para/form_helper.rb
para-0.8.5 app/helpers/para/form_helper.rb
para-0.8.3.3 app/helpers/para/form_helper.rb
para-0.8.3.2 app/helpers/para/form_helper.rb
para-0.8.3.1 app/helpers/para/form_helper.rb
para-0.8.3 app/helpers/para/form_helper.rb
para-0.8.2.3 app/helpers/para/form_helper.rb
para-0.8.2.2 app/helpers/para/form_helper.rb
para-0.8.2.1 app/helpers/para/form_helper.rb
para-0.8.2 app/helpers/para/form_helper.rb
para-0.8.1 app/helpers/para/form_helper.rb
para-0.8.0 app/helpers/para/form_helper.rb
para-0.7.4.p1 app/helpers/para/form_helper.rb
para-0.7.4 app/helpers/para/form_helper.rb