class Forma::ArrayField

Array field.

Public Class Methods

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

Public Instance Methods

edit_element(val) click to toggle source
# File lib/forma/field.rb, line 493
def edit_element(val)
  el('div', text: 'NO IMPLEMENTATION')
end
item_action(url, h={}) click to toggle source
# File lib/forma/field.rb, line 497
def item_action(url, h={})
  h[:url] = url
  @item_actions << Action.new(h)
end
view_element(val) click to toggle source
# File lib/forma/field.rb, line 484
def view_element(val)
  el('div', attrs: { class: ['ff-array-field'] }, children: val.map { |x| 
    el('div', attrs: { class: 'ff-array-part' }, children: [
      if @item_url then el('a', attrs: { href: eval_with_model(@item_url, model: x) }, text: x.to_s) else el('span', text: x.to_s) end,
      (el('span', attrs: { class: 'ff-actions' }, children: @item_actions.map { |a| a.to_html(x) } ) if @item_actions.any?)
    ])
  })
end