Class: Infold::FormElement
- Inherits:
-
Object
- Object
- Infold::FormElement
- Includes:
- ActiveModel::Model
- Defined in:
- lib/infold/property/form_element.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
Returns the value of attribute association.
-
#association_fields ⇒ Object
readonly
Returns the value of attribute association_fields.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
- #form_kind ⇒ Object
-
#in_association ⇒ Object
Returns the value of attribute in_association.
-
#seq ⇒ Object
Returns the value of attribute seq.
Instance Method Summary collapse
- #add_association_fields(field, **attrs) ⇒ Object
-
#initialize(field, **attrs) ⇒ FormElement
constructor
A new instance of FormElement.
- #kind_datetime? ⇒ Boolean
- #kind_file? ⇒ Boolean
- #kind_has_association? ⇒ Boolean
Constructor Details
#initialize(field, **attrs) ⇒ FormElement
Returns a new instance of FormElement.
14 15 16 17 18 |
# File 'lib/infold/property/form_element.rb', line 14 def initialize(field, **attrs) @field = field @association_fields = [] super(**attrs) end |
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
8 9 10 |
# File 'lib/infold/property/form_element.rb', line 8 def association @association end |
#association_fields ⇒ Object (readonly)
Returns the value of attribute association_fields.
5 6 7 |
# File 'lib/infold/property/form_element.rb', line 5 def association_fields @association_fields end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
5 6 7 |
# File 'lib/infold/property/form_element.rb', line 5 def field @field end |
#form_kind ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/infold/property/form_element.rb', line 38 def form_kind if @form_kind.to_s == 'association_search' if field.association&.belongs_to? :association_search else :text end elsif @form_kind.to_s == 'select' if field.association&.belongs_to? || field.enum.present? :select else :text end elsif kind_datetime? :datetime elsif kind_file? :file elsif field.type == :boolean :switch else (@form_kind.presence || :text).to_sym end end |
#in_association ⇒ Object
Returns the value of attribute in_association.
8 9 10 |
# File 'lib/infold/property/form_element.rb', line 8 def in_association @in_association end |
#seq ⇒ Object
Returns the value of attribute seq.
8 9 10 |
# File 'lib/infold/property/form_element.rb', line 8 def seq @seq end |
Instance Method Details
#add_association_fields(field, **attrs) ⇒ Object
20 21 22 23 24 |
# File 'lib/infold/property/form_element.rb', line 20 def add_association_fields(field, **attrs) field.build_form_element(in_association: true, **attrs) @association_fields << field field end |
#kind_datetime? ⇒ Boolean
34 35 36 |
# File 'lib/infold/property/form_element.rb', line 34 def kind_datetime? field.type.to_s == 'datetime' end |
#kind_file? ⇒ Boolean
30 31 32 |
# File 'lib/infold/property/form_element.rb', line 30 def kind_file? field.active_storage.present? || @form_kind.to_s == 'file' end |
#kind_has_association? ⇒ Boolean
26 27 28 |
# File 'lib/infold/property/form_element.rb', line 26 def kind_has_association? field.association && !field.association.belongs_to? || @form_kind.to_s == 'association' end |