Sha256: 6c4422489b342ceb89ececc5d78aaa4c69a033482462536614c38830e4c49c27

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

module ExpressTemplates
  module Components
    module Forms
      class ExpressForm < Container
        include ExpressTemplates::Components::Capabilities::Resourceful

        tag :form

        has_option :method, 'The form method', default: 'POST', attribute: true #, options: ['PUT', 'POST', 'GET', 'DELETE']
        has_option :action, 'The form action containing the resource path or url.'

        prepends -> {
          div(style: 'display:none') {
            add_child helpers.utf8_enforcer_tag
            add_child helpers.send(:method_tag, resource.persisted? ? :put : :post)
            helpers.send(:token_tag)
          }
        }

        before_build -> {
          set_attribute(:id, form_id)
          set_attribute(:action, form_action)
          add_class(config[:id])
        }

        def form_id
          [config[:id], resource.try(:id)].compact.join('_')
        end

        def form_action
          config[:action] || (resource.try(:persisted?) ? resource_path(true) : collection_path)
        end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
express_admin-1.4.10 vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb
express_admin-1.4.9 vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb
express_templates-0.9.8 lib/express_templates/components/forms/express_form.rb
express_admin-1.4.8 vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb
express_templates-0.9.7 lib/express_templates/components/forms/express_form.rb
express_admin-1.4.7 vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb
express_templates-0.9.6 lib/express_templates/components/forms/express_form.rb
express_admin-1.4.6 vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb
express_templates-0.9.5 lib/express_templates/components/forms/express_form.rb