Class: Pulse::ActionList::FormWrapper
- Defined in:
- app/components/pulse/action_list/form_wrapper.rb
Overview
Utility component for wrapping ActionLists or individual ActionList::Items in forms.
Constant Summary collapse
- DEFAULT_HTTP_METHOD =
:get- HTTP_METHOD_OPTIONS =
[ DEFAULT_HTTP_METHOD, :post, :patch, :put, :delete, :head ].freeze
Constants inherited from Component
Constants included from Pulse::AttributesHelper
Pulse::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Pulse::AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Method Summary collapse
- #form_required? ⇒ Boolean
- #get? ⇒ Boolean
-
#initialize(list:, action: nil, **form_arguments) ⇒ FormWrapper
constructor
A new instance of FormWrapper.
- #render_input? ⇒ Boolean
Methods inherited from Component
generate_id, #merge_attributes, #merge_classes
Methods included from SvgHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean
Methods included from Pulse::AttributesHelper
#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Constructor Details
#initialize(list:, action: nil, **form_arguments) ⇒ FormWrapper
Returns a new instance of FormWrapper.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/components/pulse/action_list/form_wrapper.rb', line 17 def initialize(list:, action: nil, **form_arguments) @list = list @form_arguments = form_arguments @action = action @http_method = extract_http_method(@form_arguments) name = @form_arguments.delete(:name) value = @form_arguments.delete(:value) || name @input_arguments = { type: :hidden, name:, value:, data: { list_item_input: true }, **(@form_arguments.delete(:input_arguments) || {}) } end |
Instance Method Details
#form_required? ⇒ Boolean
40 41 42 |
# File 'app/components/pulse/action_list/form_wrapper.rb', line 40 def form_required? @action && !get? end |
#get? ⇒ Boolean
36 37 38 |
# File 'app/components/pulse/action_list/form_wrapper.rb', line 36 def get? @http_method == :get end |
#render_input? ⇒ Boolean
44 45 46 |
# File 'app/components/pulse/action_list/form_wrapper.rb', line 44 def render_input? @input_arguments[:name].present? end |