Module: ProMotion::XLFormSectionBuilder

Included in:
XLForm
Defined in:
lib/ProMotion/XLForm/xl_form_section_builder.rb

Instance Method Summary collapse

Instance Method Details

#create_section(section_data) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ProMotion/XLForm/xl_form_section_builder.rb', line 4

def create_section(section_data)
  section = XLFormSectionDescriptor.section(section_data)

  tag = section_data[:name]
  if tag.respond_to? :to_s
    tag = tag.to_s
  end
  unless section.options.nil?
    mp("MutliValued section with no :name option", force_color: :red) unless tag
  end

  # force a tag for procs
  if tag.nil?
    @section_index ||= 0
    tag = "section_#{@section_index}"
  end
  section.multivaluedTag = tag

  section.footerTitle = section_data[:footer] if section_data[:footer]

  if section.multivaluedAddButton
    section.multivaluedAddButton.title = section_data[:multi_add_title] if section_data[:multi_add_title]
  end

  add_proc tag, :on_add, section_data[:on_add] if section_data[:on_add]
  add_proc tag, :on_remove, section_data[:on_remove] if section_data[:on_remove]

  # section visible
  if section_data[:hidden]
    configure_hidden(section, section_data[:hidden])
  end

  section_data[:cells].each do |cell_data|
    cell = create_cell(cell_data)

    section.addFormRow(cell)

    # multi sections
    if section.multivaluedTag
      cell.action.required = @required
      section.multivaluedRowTemplate = cell.copy
    end
  end

  section
end