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, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #url, #width
Instance Method Summary collapse
- #add_field(f) ⇒ Object
- #edit_element(val) ⇒ Object
-
#initialize(h = {}) ⇒ ComplexField
constructor
A new instance of ComplexField.
- #value ⇒ Object
- #view_element(val) ⇒ Object
Methods included from FieldHelper
#boolean_field, #combo_field, #complex_field, #date_field, #email_field, #image_field, #map_field, #number_field, #password_field, #select_field, #subform, #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, #simple_value, singular_name
Constructor Details
#initialize(h = {}) ⇒ ComplexField
Returns a new instance of ComplexField.
142 143 144 145 146 |
# File 'lib/forma/field.rb', line 142 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.
140 141 142 |
# File 'lib/forma/field.rb', line 140 def fields @fields end |
Instance Method Details
#add_field(f) ⇒ Object
148 149 150 |
# File 'lib/forma/field.rb', line 148 def add_field(f) @fields << f end |
#edit_element(val) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/forma/field.rb', line 161 def edit_element(val) el( 'div', attrs: { class: 'ff-complex-field' }, children: @fields.zip(val).map { |fv| el( 'div', attrs: { class: 'ff-field' }, children: [ fv[0].edit_element(fv[1]) ] ) } ) end |
#value ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'lib/forma/field.rb', line 152 def value val = super if val then val else @fields.each { |f| f.model = self.model } @fields.map { |f| f.value } end end |
#view_element(val) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/forma/field.rb', line 175 def view_element(val) el( 'div', attrs: { class: 'ff-complex-field' }, children: @fields.zip(val).map { |fv| el( 'div', attrs: { class: 'ff-complex-part' }, children: [ fv[0].view_element(fv[1]) ] ) } ) end |