Sha256: 42358ce16aefca76b9f4126f08bd909cb51a44156870355920b85d88e73d21aa

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

module Phlexi
  module Form
    module Components
      module Concerns
        module HasOptions
          protected

          def build_attributes
            super
            @collection = attributes.delete(:collection) || field.collection
            @label_method = attributes.delete(:label_method)
            @value_method = attributes.delete(:value_method)
          end

          def option_mapper
            @option_mapper ||= OptionMapper.new(@collection, label_method: @label_method, value_method: @value_method)
          end

          def selected?(option)
            if field.multiple?
              @options_list ||= Array(field.value)
              @options_list.any? { |item| item.to_s == option.to_s }
            else
              field.dom.value == option.to_s
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phlexi-form-0.2.0 lib/phlexi/form/components/concerns/has_options.rb