Module: CustomFormGenerator::Helpers::FormElementRenderer

Included in:
Generator, CustomFormGenerator::Helpers
Defined in:
lib/custom_form_generator/helpers/form_element_renderer.rb

Overview

FormElementRenderer module handles HTML form element generation

Instance Method Summary collapse

Instance Method Details

#render_datetime(field, attrs) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/custom_form_generator/helpers/form_element_renderer.rb', line 28

def render_datetime(field, attrs)
  disabled_attr = field["disabled"] ? "disabled" : ""
  <<~HTML
    <label for='#{attrs[:id]}'>#{attrs[:label]}</label>
    <input type='datetime-local' id='#{attrs[:id]}' class='#{attrs[:css_class]}'#{" "}
           name='#{attrs[:key]}' value='#{CGI.escapeHTML(attrs[:value])}' #{disabled_attr} />
  HTML
end

#render_dropdown(field, attrs) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/custom_form_generator/helpers/form_element_renderer.rb', line 18

def render_dropdown(field, attrs)
  options = fetch_dropdown_options(field, attrs[:value])
  <<~HTML
    <label for='#{attrs[:id]}'>#{attrs[:label]}</label>
    <select id='#{attrs[:id]}' class='#{attrs[:css_class]}' name='#{attrs[:key]}'>
      #{options}
    </select>
  HTML
end

#render_radio(field, attrs) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/custom_form_generator/helpers/form_element_renderer.rb', line 37

def render_radio(field, attrs)
  options = fetch_radio_options(field, attrs[:value])
  <<~HTML
    <fieldset>
      <legend>#{attrs[:label]}</legend>
      #{options}
    </fieldset>
  HTML
end

#render_textbox(attrs) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/custom_form_generator/helpers/form_element_renderer.rb', line 47

def render_textbox(attrs)
  <<~HTML
    <label for='#{attrs[:id]}'>#{attrs[:label]}</label>
    <textarea id='#{attrs[:id]}' class='#{attrs[:css_class]}' name='#{attrs[:key]}'#{" "}
              placeholder='Enter your #{attrs[:label]}'>#{CGI.escapeHTML(attrs[:value])}</textarea>
  HTML
end

#render_textfield(attrs) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/custom_form_generator/helpers/form_element_renderer.rb', line 9

def render_textfield(attrs)
  <<~HTML
    <label for='#{attrs[:id]}'>#{attrs[:label]}</label>
    <input type='text' id='#{attrs[:id]}' class='#{attrs[:css_class]}'#{" "}
           name='#{attrs[:key]}' value='#{CGI.escapeHTML(attrs[:value])}'#{" "}
           placeholder='Enter your #{attrs[:label]}'/>
  HTML
end