Module: JotForm::Helpers

Defined in:
lib/jotform/helpers.rb,
lib/jotform/helpers/forms.rb

Instance Method Summary collapse

Instance Method Details

#input_type(question) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/jotform/helpers/forms.rb', line 30

def input_type(question)
  case question[:type]
  when 'control_textbox'  then 'text'
  when 'control_dropdown' then 'select'
  when 'control_button'   then 'button'
  when 'control_textarea' then 'textarea'
  end
end

#render_form(form) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/jotform/helpers/forms.rb', line 3

def render_form(form)
  capture_haml do
    haml_tag :form, {:method => 'post', :action => form.submission_url, :'accept-charset' => 'utf-8'} do |f|
      haml_tag :input, {:type => 'hidden', :name => 'formID', :value => form.id}
      haml_tag :div, {:class => 'form-structure'} do |h|
        render_questions(form)
      end
      haml_tag :input, {:type => 'hidden', :name => 'website', :value => ""}
      haml_tag :input, {:type => 'hidden', :name => 'simple_spc', :value => "#{form.id}-#{form.id}"}
    end
  end
end

#render_input(question) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/jotform/helpers/forms.rb', line 55

def render_input(question)
  case input_type(question)
  when 'select'
    haml_tag :select, {:name => "q#{question[:qid]}_#{question[:name]}", :id => "input_#{question[:qid]}"} do |h|
      haml_tag :option, ' '
      question[:options].split('|').each do |o|
        haml_tag :option, o, {:value => o}
      end
    end
  when 'button'
    haml_tag :button, question[:text], {:type => 'submit', :id => "input_#{question[:qid]}"}
  when 'textarea'
    haml_tag :textarea, {:name => "q#{question[:qid]}_#{question[:name]}", :id => "input_#{question[:qid]}"}
  else
    haml_tag :input, {:type => 'text', :name => "q#{question[:qid]}_#{question[:name]}", :id => "input_#{question[:qid]}"}
  end
end

#render_label(question) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jotform/helpers/forms.rb', line 39

def render_label(question)
  unless input_type(question) == 'button'
    label_class = question[:subLabel].blank? ? '' : 'with-note'
    haml_tag :label, {:class => label_class, :for => "input_#{question[:qid]}"} do |h|
      haml_concat question[:text]
      haml_tag :span, question[:subLabel], {:class => 'note'} unless question[:subLabel].blank?
    end

    unless question[:hint].blank?
      haml_tag :label, {:class => 'hint', :for => "input_#{question[:qid]}"} do |h|
        haml_concat question[:hint]
      end
    end
  end
end

#render_questions(form) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jotform/helpers/forms.rb', line 16

def render_questions(form)
  form.questions.each do |question|

    type_class      = input_type(question)
    required_class  = 'required'  if question[:required]
    size_class      = 'short'     if question[:size].to_i < 6

    haml_tag :div, {:class => "field #{type_class} #{size_class} #{required_class}", :id => "field_#{question[:name]}"} do |h|
      render_label(question)
      render_input(question)
    end
  end
end