Class: CmAdmin::Models::FormField
- Inherits:
-
Object
- Object
- CmAdmin::Models::FormField
- Defined in:
- lib/cm_admin/models/form_field.rb
Constant Summary collapse
- VALID_INPUT_TYPES =
[:integer, :decimal, :string, :single_select, :multi_select, :date, :date_time, :text, :single_file_upload, :multi_file_upload, :hidden, :rich_text].freeze
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#display_if ⇒ Object
Returns the value of attribute display_if.
-
#field_name ⇒ Object
Returns the value of attribute field_name.
-
#header ⇒ Object
Returns the value of attribute header.
-
#helper_method ⇒ Object
Returns the value of attribute helper_method.
-
#html_attr ⇒ Object
Returns the value of attribute html_attr.
-
#input_type ⇒ Object
Returns the value of attribute input_type.
-
#label ⇒ Object
Returns the value of attribute label.
-
#placeholder ⇒ Object
Returns the value of attribute placeholder.
Instance Method Summary collapse
-
#initialize(field_name, input_type, attributes = {}) ⇒ FormField
constructor
A new instance of FormField.
- #set_default_values ⇒ Object
Constructor Details
#initialize(field_name, input_type, attributes = {}) ⇒ FormField
Returns a new instance of FormField.
7 8 9 10 11 12 13 14 15 |
# File 'lib/cm_admin/models/form_field.rb', line 7 def initialize(field_name, input_type, attributes = {}) @field_name = field_name set_default_values attributes.each do |key, value| self.send("#{key.to_s}=", value) end self.display_if = lambda { |arg| return true } if self.display_if.nil? raise ArgumentError, "Kindly select a valid input type like #{VALID_INPUT_TYPES.sort.to_sentence(last_word_connector: ', or ')} instead of #{self.input_type} for form field #{field_name}" unless VALID_INPUT_TYPES.include?(self.input_type.to_sym) end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def collection @collection end |
#disabled ⇒ Object
Returns the value of attribute disabled.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def disabled @disabled end |
#display_if ⇒ Object
Returns the value of attribute display_if.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def display_if @display_if end |
#field_name ⇒ Object
Returns the value of attribute field_name.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def field_name @field_name end |
#header ⇒ Object
Returns the value of attribute header.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def header @header end |
#helper_method ⇒ Object
Returns the value of attribute helper_method.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def helper_method @helper_method end |
#html_attr ⇒ Object
Returns the value of attribute html_attr.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def html_attr @html_attr end |
#input_type ⇒ Object
Returns the value of attribute input_type.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def input_type @input_type end |
#label ⇒ Object
Returns the value of attribute label.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def label @label end |
#placeholder ⇒ Object
Returns the value of attribute placeholder.
4 5 6 |
# File 'lib/cm_admin/models/form_field.rb', line 4 def placeholder @placeholder end |
Instance Method Details
#set_default_values ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cm_admin/models/form_field.rb', line 17 def set_default_values self.disabled = false self.label = self.field_name.to_s.titleize self.input_type = :string self.placeholder = "Enter #{self.field_name.to_s.downcase.gsub('_', ' ')}" self.html_attr = {} end |