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, #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.
135 136 137 138 139 |
# File 'lib/forma/field.rb', line 135 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.
133 134 135 |
# File 'lib/forma/field.rb', line 133 def fields @fields end |
Instance Method Details
#add_field(f) ⇒ Object
141 142 143 |
# File 'lib/forma/field.rb', line 141 def add_field(f) @fields << f end |
#edit_element(val) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/forma/field.rb', line 149 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
172 173 174 |
# File 'lib/forma/field.rb', line 172 def errors @fields.map { |f| f.model = @model; f.errors }.flatten end |
#has_errors? ⇒ Boolean
176 177 178 |
# File 'lib/forma/field.rb', line 176 def has_errors? errors.any? end |
#value ⇒ Object
145 146 147 |
# File 'lib/forma/field.rb', line 145 def value @model end |
#view_element(val) ⇒ Object
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/forma/field.rb', line 161 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 |