Sha256: d9f1e875d307e3d7d4ed9308e79fb9d96b4c6c79ca27d3feb7b9db46b8e850ff

Contents?: true

Size: 1.45 KB

Versions: 32

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Phlexi
  module Form
    module Components
      module Concerns
        module ExtractsInput
          # Collects parameters matching the input field's param key.
          #
          # @param params [Hash] the parameters to collect from.
          # @return [Hash] the collected parameters.
          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

          protected

          def build_attributes
            super
            @input_param = attributes.delete(:input_param) || field.key
          end

          def input_param
            @input_param
          end

          def normalize_input(input_value)
            normalize_simple_input(input_value)
          end

          def normalize_simple_input(input_value)
            input_value.to_s.presence
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
phlexi-form-0.8.3 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.8.2 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.8.1 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.8.0 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.7.2 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.7.1 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.7.0 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.6.2 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.6.1 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.6.0 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.11 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.10 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.9 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.8 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.7 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.6 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.5 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.4 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.3 lib/phlexi/form/components/concerns/extracts_input.rb
phlexi-form-0.5.2 lib/phlexi/form/components/concerns/extracts_input.rb