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