Sha256: 1c96f35a8292be217cea30db191999205e6b73b0079cd1f35275fae02ae4d8b0

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 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.'
        has_option :on_success, 'Pass a form value indicating where to go on a successful submission.'
        has_option :on_failure, 'Pass a form value indicating where to go on a failed submission.'

        prepends -> {
          div(style: 'display:none') {
            add_child helpers.utf8_enforcer_tag
            add_child helpers.send(:method_tag, resource.persisted? ? :put : :post)
            add_child helpers.send(:token_tag)
            hidden_field_tag :on_success, config[:on_success] if config[:on_success]
            hidden_field_tag :on_failure, config[:on_failure] if config[:on_failure]
          }
        }

        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(resource) : collection_path)
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
express_admin-1.6.0 vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb
express_templates-0.10.1 lib/express_templates/components/forms/express_form.rb
express_admin-1.5.0 vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb
express_admin-1.4.11 vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb