Module: Phlexi::Form::Components::Concerns::ExtractsInput

Included in:
HandlesInput, SubmitsForm
Defined in:
lib/phlexi/form/components/concerns/extracts_input.rb

Instance Method Summary collapse

Instance Method Details

#extract_input(params) ⇒ Hash

Collects parameters matching the input field’s param key.

Parameters:

  • params (Hash)

    the parameters to collect from.

Returns:

  • (Hash)

    the collected parameters.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/phlexi/form/components/concerns/extracts_input.rb', line 12

def extract_input(params)
  # # Handles multi parameter attributes
  # # https://www.cookieshq.co.uk/posts/rails-spelunking-date-select
  # # https://www.cookieshq.co.uk/posts/multiparameter-attributes

  # # Matches
  # # - parameter
  # # - parameter(1)
  # # - parameter(2)
  # # - parameter(1i)
  # # - parameter(2f)
  # regex = /^#{param}(\(\d+[if]?\))?$/
  # keys = params.select { |key, _| regex.match?(key) }.keys
  # params.slice(*keys)

  params ||= {}
  {input_param => normalize_input(params[field.key])}
end