Class: SexyForm::Themes::Bootstrap2Vertical

Inherits:
BaseTheme
  • Object
show all
Defined in:
lib/sexy_form/themes/bootstrap_2_vertical.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.theme_nameObject



5
6
7
# File 'lib/sexy_form/themes/bootstrap_2_vertical.rb', line 5

def self.theme_name
  "bootstrap_2_vertical"
end

Instance Method Details

#build_html_error(error:, html_attrs:, field_type:) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/sexy_form/themes/bootstrap_2_vertical.rb', line 68

def build_html_error(error:, html_attrs:, field_type:)
  html_attrs["class"] = "help-block #{html_attrs["class"]}".strip

  s = ""
  s << (html_attrs.empty? ? "<span>" : "<span #{SexyForm.build_html_attr_string(html_attrs)}>")
  s << "#{error}"
  s << "</span>"
  s
end

#build_html_help_text(help_text:, html_attrs:, field_type:) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/sexy_form/themes/bootstrap_2_vertical.rb', line 58

def build_html_help_text(help_text:, html_attrs:, field_type:)
  html_attrs["class"] = "help-block #{html_attrs["class"]}".strip

  s = ""
  s << (html_attrs.empty? ? "<span>" : "<span #{SexyForm.build_html_attr_string(html_attrs)}>")
  s << "#{help_text}"
  s << "</span>"
  s
end

#form_html_attributes(html_attrs:) ⇒ Object



54
55
56
# File 'lib/sexy_form/themes/bootstrap_2_vertical.rb', line 54

def form_html_attributes(html_attrs:)
  html_attrs
end

#input_html_attributes(html_attrs:, field_type:, has_errors:) ⇒ Object



40
41
42
# File 'lib/sexy_form/themes/bootstrap_2_vertical.rb', line 40

def input_html_attributes(html_attrs:, field_type:, has_errors:)
  html_attrs
end

#label_html_attributes(html_attrs:, field_type:, has_errors:) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/sexy_form/themes/bootstrap_2_vertical.rb', line 44

def label_html_attributes(html_attrs:, field_type:, has_errors:)
  if ["checkbox", "radio"].include?(field_type)
    html_attrs["class"] = "#{field_type} #{html_attrs["class"]}".strip
  else
    html_attrs["class"] = "control-label #{html_attrs["class"]}".strip
  end

  html_attrs
end

#wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:) ⇒ Object



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
# File 'lib/sexy_form/themes/bootstrap_2_vertical.rb', line 9

def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:)
  s = ""

  wrapper_html_attributes["class"] = "control-group#{" error" if html_errors} #{wrapper_html_attributes["class"]}".strip

  attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes)
  s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}"

  if ["checkbox", "radio"].include?(field_type)
    s << %Q(<div class="controls">)

    if html_label
      s << html_label.sub("\">", "\">#{html_field} ")
    else
      s << "#{html_field}"
    end
  else
    s << "#{html_label}"
    s << %Q(<div class="controls">)
    s << "#{html_field}"
  end

  s << "#{html_help_text}"
  s << html_errors.join if html_errors

  s << "</div>"
  s << "</div>"

  s
end