class Forma::ComplexField

Complex field.

Attributes

fields[R]

Public Class Methods

new(h = {}) click to toggle source
Calls superclass method Forma::Field::new
# File lib/forma/field.rb, line 140
def initialize(h = {})
  h = h.symbolize_keys
  @fields = h[:fields] || []
  super(h)
end

Public Instance Methods

add_field(f) click to toggle source
# File lib/forma/field.rb, line 146
def add_field(f)
  @fields << f
end
edit_element(val) click to toggle source
# File lib/forma/field.rb, line 154
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() click to toggle source
# File lib/forma/field.rb, line 177
def errors
  @fields.map { |f| f.model = @model; f.errors }.flatten
end
has_errors?() click to toggle source
# File lib/forma/field.rb, line 181
def has_errors?
  errors.any?
end
value() click to toggle source
# File lib/forma/field.rb, line 150
def value
  @model
end
view_element(val) click to toggle source
# File lib/forma/field.rb, line 166
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