Class: Katalyst::Tables::Orderable::FormComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
Identifiable::Defaults
Defined in:
app/components/katalyst/tables/orderable/form_component.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Identifiable::Defaults

#default_table_id

Constructor Details

#initialize(collection:, url:, id: nil, scope: nil) ⇒ FormComponent

Returns a new instance of FormComponent.

Parameters:

  • collection (Katalyst::Tables::Collection::Core)

    the collection to render

  • url (String)

    the url to submit the form to (e.g. <resources>_order_path)

  • id (String) (defaults to: nil)

    the id of the form element (defaults to <resources>_order_form)

  • scope (String) (defaults to: nil)

    the base scope to use for form inputs (defaults to order)



15
16
17
18
19
20
21
# File 'app/components/katalyst/tables/orderable/form_component.rb', line 15

def initialize(collection:, url:, id: nil, scope: nil)
  super

  @id    = id || Orderable.default_form_id(collection)
  @url   = url
  @scope = scope || Orderable.default_scope(collection)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'app/components/katalyst/tables/orderable/form_component.rb', line 9

def id
  @id
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'app/components/katalyst/tables/orderable/form_component.rb', line 9

def url
  @url
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
# File 'app/components/katalyst/tables/orderable/form_component.rb', line 23

def call
  form_with(id:, url:, method: :patch, data: {
              controller:                       FORM_CONTROLLER,
              "#{FORM_CONTROLLER}-scope-value": @scope,
            }) do |form|
    form.button(hidden: "")
  end
end

#inspectObject



32
33
34
# File 'app/components/katalyst/tables/orderable/form_component.rb', line 32

def inspect
  "#<#{self.class.name} id: #{id.inspect}, url: #{url.inspect}>"
end