Class: Formbuilder::Views::Form

Inherits:
Erector::Widget
  • Object
show all
Defined in:
lib/formbuilder/views/form.rb

Instance Method Summary collapse

Instance Method Details

#actionsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/formbuilder/views/form.rb', line 33

def actions
  opts = {}

  unless first_page?
    opts[:go_back_text] = "Back to page #{previous_page}"
    opts[:go_back_html] = { href: url_for(params.merge(page: previous_page)) }
  end

  if last_page?
    opts[:continue_text] = 'Preview and Submit'
  else
    opts[:continue_text] = 'Next page'
  end

  div(class: 'form-actions') {
    if opts[:go_back_text]
      a.button opts[:go_back_text], opts[:go_back_html]
    end

    button.button.primary opts[:continue_text]
  }
end

#contentObject



11
12
13
14
15
16
17
18
19
# File 'lib/formbuilder/views/form.rb', line 11

def content
  page_list if @form.multi_page?

  form_tag @action, method: @method, class: 'formbuilder-form', multipart: true do
    input type: 'hidden', name: 'page', value: @current_page
    render_fields
    actions
  end
end

#page_listObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/formbuilder/views/form.rb', line 21

def page_list
  ul.unstyled.inline.formbuilder_form_pages_list {
    (1..@form.num_pages).each do |x|
      if x == @current_page
        li { span x }
      else
        li.active { a x, href: url_for(params.merge(page: x)) }
      end
    end
  }
end