Sha256: 631623e8e71f3a09c555e50ceb75593de46956370c110b8d3fc92d81b6a46b73

Contents?: true

Size: 879 Bytes

Versions: 9

Compression:

Stored size: 879 Bytes

Contents

module CmAdmin
  module Models
    class FormField
      attr_accessor :field_name, :label, :header, :input_type, :collection, :custom_value, :disabled
      VALID_INPUT_TYPES = [:integer, :decimal, :string, :single_select, :multi_select, :date, :date_time, :text, :single_file_upload, :multi_file_upload, :hidden].freeze

      def initialize(field_name, input_type, attributes = {})
        raise ArgumentError, "Kindly select a valid filter type like #{VALID_INPUT_TYPES.sort.to_sentence(last_word_connector: ', or ')} instead of #{input_type} for column #{field_name}" unless VALID_INPUT_TYPES.include?(input_type.to_sym)
        @field_name = field_name
        set_default_values
        attributes.each do |key, value|
          self.send("#{key.to_s}=", value)
        end
      end

      def set_default_values
        self.disabled = false
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cm-admin-0.5.4 lib/cm_admin/models/form_field.rb
cm-admin-0.5.3 lib/cm_admin/models/form_field.rb
cm-admin-0.5.2 lib/cm_admin/models/form_field.rb
cm-admin-0.5.0 lib/cm_admin/models/form_field.rb
cm-admin-0.4.4 lib/cm_admin/models/form_field.rb
cm-admin-0.4.3 lib/cm_admin/models/form_field.rb
cm-admin-0.4.2 lib/cm_admin/models/form_field.rb
cm-admin-0.4.1 lib/cm_admin/models/form_field.rb
cm-admin-0.4.0 lib/cm_admin/models/form_field.rb