Class: Forma::ComplexField
- Includes:
- FieldHelper
- Defined in:
- lib/forma/field.rb
Overview
Complex field.
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Attributes inherited from Field
#actions, #after, #autofocus, #before, #child_model_name, #height, #hint, #i18n, #icon, #inline_hint, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #turbolink, #url, #width
Instance Method Summary collapse
- #add_field(f) ⇒ Object
- #edit_element(val) ⇒ Object
- #errors ⇒ Object
- #has_errors? ⇒ Boolean
-
#initialize(h = {}) ⇒ ComplexField
constructor
A new instance of ComplexField.
- #value ⇒ Object
- #view_element(val) ⇒ Object
Methods included from FieldHelper
#array_field, #boolean_field, #combo_field, #complex_field, #date_field, #email_field, #file_field, #image_field, #map_field, #number_field, #password_field, #select_field, #subform, #table_field, #text_field
Methods inherited from Field
#action, #id, #localization_key, #localized_hint, #localized_label, #name_as_chain, #parameter_name, #to_html
Methods included from Html
Methods included from Utils
extract_value, number_format, #simple_value, singular_name
Constructor Details
#initialize(h = {}) ⇒ ComplexField
Returns a new instance of ComplexField.
141 142 143 144 145 |
# File 'lib/forma/field.rb', line 141 def initialize(h = {}) h = h.symbolize_keys @fields = h[:fields] || [] super(h) end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
139 140 141 |
# File 'lib/forma/field.rb', line 139 def fields @fields end |
Instance Method Details
#add_field(f) ⇒ Object
147 148 149 |
# File 'lib/forma/field.rb', line 147 def add_field(f) @fields << f end |
#edit_element(val) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/forma/field.rb', line 155 def edit_element(val) el( 'div', attrs: { class: 'ff-complex-field' }, children: @fields.map { |f| f.model = self.model f.model_name = self.model_name el('div', attrs: { class: 'ff-complex-part' }, children: [ f.to_html(true) ]) } ) end |
#errors ⇒ Object
178 179 180 |
# File 'lib/forma/field.rb', line 178 def errors @fields.map { |f| f.model = @model; f.errors }.flatten end |
#has_errors? ⇒ Boolean
182 183 184 |
# File 'lib/forma/field.rb', line 182 def has_errors? errors.any? end |
#value ⇒ Object
151 152 153 |
# File 'lib/forma/field.rb', line 151 def value @model end |
#view_element(val) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/forma/field.rb', line 167 def view_element(val) el( 'div', attrs: { class: 'ff-complex-field' }, children: @fields.map { |f| f.model = self.model el('div', attrs: { class: 'ff-complex-part' }, children: [ f.to_html(false) ]) } ) end |