sexy_form 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +275 -0
- data/Rakefile +15 -0
- data/lib/sexy_form.rb +84 -0
- data/lib/sexy_form/builder.rb +306 -0
- data/lib/sexy_form/themes.rb +22 -0
- data/lib/sexy_form/themes/base_theme.rb +39 -0
- data/lib/sexy_form/themes/bootstrap_2_horizontal.rb +83 -0
- data/lib/sexy_form/themes/bootstrap_2_inline.rb +73 -0
- data/lib/sexy_form/themes/bootstrap_2_vertical.rb +80 -0
- data/lib/sexy_form/themes/bootstrap_3_horizontal.rb +95 -0
- data/lib/sexy_form/themes/bootstrap_3_inline.rb +71 -0
- data/lib/sexy_form/themes/bootstrap_3_vertical.rb +70 -0
- data/lib/sexy_form/themes/bootstrap_4_horizontal.rb +95 -0
- data/lib/sexy_form/themes/bootstrap_4_inline.rb +80 -0
- data/lib/sexy_form/themes/bootstrap_4_vertical.rb +79 -0
- data/lib/sexy_form/themes/bulma_horizontal.rb +81 -0
- data/lib/sexy_form/themes/bulma_vertical.rb +73 -0
- data/lib/sexy_form/themes/default.rb +55 -0
- data/lib/sexy_form/themes/foundation.rb +67 -0
- data/lib/sexy_form/themes/materialize.rb +65 -0
- data/lib/sexy_form/themes/milligram.rb +62 -0
- data/lib/sexy_form/themes/semantic_ui_inline.rb +63 -0
- data/lib/sexy_form/themes/semantic_ui_vertical.rb +63 -0
- data/lib/sexy_form/version.rb +3 -0
- data/spec/custom_assertions.rb +21 -0
- data/spec/sexy_form/builder_spec.rb +104 -0
- data/spec/sexy_form/themes/base_theme_spec.rb +16 -0
- data/spec/sexy_form/themes/bootstrap_2_horizontal_spec.rb +114 -0
- data/spec/sexy_form/themes/bootstrap_2_inline_spec.rb +108 -0
- data/spec/sexy_form/themes/bootstrap_2_vertical_spec.rb +111 -0
- data/spec/sexy_form/themes/bootstrap_3_horizontal_spec.rb +116 -0
- data/spec/sexy_form/themes/bootstrap_3_inline_spec.rb +104 -0
- data/spec/sexy_form/themes/bootstrap_3_vertical_spec.rb +122 -0
- data/spec/sexy_form/themes/bootstrap_4_horizontal_spec.rb +124 -0
- data/spec/sexy_form/themes/bootstrap_4_inline_spec.rb +116 -0
- data/spec/sexy_form/themes/bootstrap_4_vertical_spec.rb +114 -0
- data/spec/sexy_form/themes/bulma_horizontal_spec.rb +126 -0
- data/spec/sexy_form/themes/bulma_vertical_spec.rb +114 -0
- data/spec/sexy_form/themes/default_spec.rb +102 -0
- data/spec/sexy_form/themes/foundation_spec.rb +103 -0
- data/spec/sexy_form/themes/materialize_spec.rb +103 -0
- data/spec/sexy_form/themes/milligram_spec.rb +120 -0
- data/spec/sexy_form/themes/semantic_ui_inline_spec.rb +105 -0
- data/spec/sexy_form/themes/semantic_ui_vertical_spec.rb +105 -0
- data/spec/sexy_form/themes/theme_spec_helper.rb +0 -0
- data/spec/sexy_form/themes_spec.rb +52 -0
- data/spec/sexy_form_spec.rb +54 -0
- data/spec/spec_helper.rb +16 -0
- metadata +160 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
module SexyForm
|
2
|
+
module Themes
|
3
|
+
class Bootstrap3Vertical < BaseTheme
|
4
|
+
|
5
|
+
def self.theme_name
|
6
|
+
"bootstrap_3_vertical"
|
7
|
+
end
|
8
|
+
|
9
|
+
def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:)
|
10
|
+
s = ""
|
11
|
+
|
12
|
+
wrapper_html_attributes["class"] = "form-group#{" has-error" if html_errors} #{wrapper_html_attributes["class"]}".strip
|
13
|
+
|
14
|
+
attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes)
|
15
|
+
s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}"
|
16
|
+
|
17
|
+
if ["checkbox", "radio"].include?(field_type)
|
18
|
+
if html_label
|
19
|
+
s << html_label.sub("\">", "\">#{html_field} ")
|
20
|
+
else
|
21
|
+
s << "#{html_field}"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
s << "#{html_label}"
|
25
|
+
s << "#{html_field}"
|
26
|
+
end
|
27
|
+
|
28
|
+
s << "#{html_help_text}"
|
29
|
+
s << html_errors.join if html_errors
|
30
|
+
|
31
|
+
s << "</div>"
|
32
|
+
|
33
|
+
s
|
34
|
+
end
|
35
|
+
|
36
|
+
def input_html_attributes(html_attrs:, field_type:, has_errors:)
|
37
|
+
html_attrs
|
38
|
+
end
|
39
|
+
|
40
|
+
def label_html_attributes(html_attrs:, field_type:, has_errors:)
|
41
|
+
html_attrs
|
42
|
+
end
|
43
|
+
|
44
|
+
def form_html_attributes(html_attrs:)
|
45
|
+
html_attrs
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_html_help_text(help_text:, html_attrs:, field_type:)
|
49
|
+
html_attrs["class"] = "help-block #{html_attrs["class"]}".strip
|
50
|
+
|
51
|
+
s = ""
|
52
|
+
s << (html_attrs.empty? ? "<span>" : "<span #{SexyForm.build_html_attr_string(html_attrs)}>")
|
53
|
+
s << "#{help_text}"
|
54
|
+
s << "</span>"
|
55
|
+
s
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_html_error(error:, html_attrs:, field_type:)
|
59
|
+
html_attrs["class"] = "help-block #{html_attrs["class"]}".strip
|
60
|
+
|
61
|
+
s = ""
|
62
|
+
s << (html_attrs.empty? ? "<span>" : "<span #{SexyForm.build_html_attr_string(html_attrs)}>")
|
63
|
+
s << "#{error}"
|
64
|
+
s << "</span>"
|
65
|
+
s
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module SexyForm
|
2
|
+
module Themes
|
3
|
+
class Bootstrap4Horizontal < BaseTheme
|
4
|
+
|
5
|
+
def self.theme_name
|
6
|
+
"bootstrap_4_horizontal"
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(column_classes: ["col-sm-3", "col-sm-9"])
|
10
|
+
@column_classes = column_classes.first(2)
|
11
|
+
|
12
|
+
s = "#{@column_classes[0]}"
|
13
|
+
@offset_class = (i = s.index(/-\d/)) ? s.insert(i+1, "offset-") : ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:)
|
17
|
+
s = ""
|
18
|
+
|
19
|
+
wrapper_html_attributes["class"] = "form-group row #{wrapper_html_attributes["class"]}".strip
|
20
|
+
|
21
|
+
attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes)
|
22
|
+
s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}"
|
23
|
+
|
24
|
+
if ["checkbox", "radio"].include?(field_type)
|
25
|
+
s << %Q(<div class="#{@offset_class} #{@column_classes[1]}">)
|
26
|
+
s << %Q(<div class="form-check">)
|
27
|
+
s << "#{html_field}"
|
28
|
+
s << "#{html_label}"
|
29
|
+
s << "#{html_help_text}"
|
30
|
+
s << html_errors.join if html_errors
|
31
|
+
s << "</div>"
|
32
|
+
s << "</div>"
|
33
|
+
else
|
34
|
+
s << "#{html_label}"
|
35
|
+
s << %Q(<div class="#{"#{@offset_class} " unless html_label}#{@column_classes[1]}">)
|
36
|
+
s << "#{html_field}"
|
37
|
+
s << "#{html_help_text}"
|
38
|
+
s << html_errors.join if html_errors
|
39
|
+
s << "</div>"
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
s << "</div>"
|
44
|
+
end
|
45
|
+
|
46
|
+
def input_html_attributes(html_attrs:, field_type:, has_errors:)
|
47
|
+
case field_type
|
48
|
+
when "checkbox", "radio"
|
49
|
+
html_attrs["class"] = "form-check-input#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
50
|
+
when "file"
|
51
|
+
html_attrs["class"] = "form-control-file#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
52
|
+
else
|
53
|
+
html_attrs["class"] = "form-control#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
54
|
+
end
|
55
|
+
|
56
|
+
html_attrs
|
57
|
+
end
|
58
|
+
|
59
|
+
def label_html_attributes(html_attrs:, field_type:, has_errors:)
|
60
|
+
if ["checkbox", "radio"].include?(field_type)
|
61
|
+
html_attrs["class"] = "form-check-label #{html_attrs["class"]}".strip
|
62
|
+
else
|
63
|
+
html_attrs["class"] = "#{@column_classes[0]} col-form-label #{html_attrs["class"]}".strip
|
64
|
+
end
|
65
|
+
|
66
|
+
html_attrs
|
67
|
+
end
|
68
|
+
|
69
|
+
def form_html_attributes(html_attrs:)
|
70
|
+
html_attrs
|
71
|
+
end
|
72
|
+
|
73
|
+
def build_html_help_text(help_text:, html_attrs:, field_type:)
|
74
|
+
html_attrs["class"] = "form-text #{html_attrs["class"]}".strip
|
75
|
+
|
76
|
+
s = ""
|
77
|
+
s << (html_attrs.empty? ? "<small>" : "<small #{SexyForm.build_html_attr_string(html_attrs)}>")
|
78
|
+
s << "#{help_text}"
|
79
|
+
s << "</small>"
|
80
|
+
s
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_html_error(error:, html_attrs:, field_type:)
|
84
|
+
html_attrs["class"] = "invalid-feedback #{html_attrs["class"]}".strip
|
85
|
+
|
86
|
+
s = ""
|
87
|
+
s << (html_attrs.empty? ? "<div>" : "<div #{SexyForm.build_html_attr_string(html_attrs)}>")
|
88
|
+
s << "#{error}"
|
89
|
+
s << "</div>"
|
90
|
+
s
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module SexyForm
|
2
|
+
module Themes
|
3
|
+
class Bootstrap4Inline < BaseTheme
|
4
|
+
|
5
|
+
def self.theme_name
|
6
|
+
"bootstrap_4_inline"
|
7
|
+
end
|
8
|
+
|
9
|
+
def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:)
|
10
|
+
s = ""
|
11
|
+
|
12
|
+
wrapper_html_attributes["class"] = "form-group #{"form-check" if ["checkbox", "radio"].include?(field_type)} #{wrapper_html_attributes["class"]}".strip
|
13
|
+
|
14
|
+
attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes)
|
15
|
+
s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}"
|
16
|
+
|
17
|
+
if ["checkbox", "radio"].include?(field_type)
|
18
|
+
s << "#{html_field}"
|
19
|
+
s << "#{html_label}"
|
20
|
+
else
|
21
|
+
s << "#{html_label}"
|
22
|
+
s << "#{html_field}"
|
23
|
+
end
|
24
|
+
s << "#{html_help_text}"
|
25
|
+
s << html_errors.join if html_errors
|
26
|
+
|
27
|
+
s << "</div>"
|
28
|
+
|
29
|
+
s
|
30
|
+
end
|
31
|
+
|
32
|
+
def input_html_attributes(html_attrs:, field_type:, has_errors:)
|
33
|
+
case field_type
|
34
|
+
when "checkbox", "radio"
|
35
|
+
html_attrs["class"] = "form-check-input#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
36
|
+
when "file"
|
37
|
+
html_attrs["class"] = "form-control-file#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
38
|
+
else
|
39
|
+
html_attrs["class"] = "form-control#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
40
|
+
end
|
41
|
+
|
42
|
+
html_attrs
|
43
|
+
end
|
44
|
+
|
45
|
+
def label_html_attributes(html_attrs:, field_type:, has_errors:)
|
46
|
+
if ["checkbox", "radio"].include?(field_type)
|
47
|
+
html_attrs["class"] = "form-check-label #{html_attrs["class"]}".strip
|
48
|
+
end
|
49
|
+
|
50
|
+
html_attrs
|
51
|
+
end
|
52
|
+
|
53
|
+
def form_html_attributes(html_attrs:)
|
54
|
+
html_attrs["class"] = "form-inline #{html_attrs["class"]}".strip
|
55
|
+
html_attrs
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_html_help_text(help_text:, html_attrs:, field_type:)
|
59
|
+
html_attrs["class"] = "form-text #{html_attrs["class"]}".strip
|
60
|
+
|
61
|
+
s = ""
|
62
|
+
s << (html_attrs.empty? ? "<small>" : "<small #{SexyForm.build_html_attr_string(html_attrs)}>")
|
63
|
+
s << "#{help_text}"
|
64
|
+
s << "</small>"
|
65
|
+
s
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_html_error(error:, html_attrs:, field_type:)
|
69
|
+
html_attrs["class"] = "invalid-feedback #{html_attrs["class"]}".strip
|
70
|
+
|
71
|
+
s = ""
|
72
|
+
s << (html_attrs.empty? ? "<div>" : "<div #{SexyForm.build_html_attr_string(html_attrs)}>")
|
73
|
+
s << "#{error}"
|
74
|
+
s << "</div>"
|
75
|
+
s
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module SexyForm
|
2
|
+
module Themes
|
3
|
+
class Bootstrap4Vertical < BaseTheme
|
4
|
+
|
5
|
+
def self.theme_name
|
6
|
+
"bootstrap_4_vertical"
|
7
|
+
end
|
8
|
+
|
9
|
+
def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:)
|
10
|
+
s = ""
|
11
|
+
|
12
|
+
wrapper_html_attributes["class"] = "form-group #{"form-check" if ["checkbox", "radio"].include?(field_type)} #{wrapper_html_attributes["class"]}".strip
|
13
|
+
|
14
|
+
attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes)
|
15
|
+
s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}"
|
16
|
+
|
17
|
+
if ["checkbox", "radio"].include?(field_type)
|
18
|
+
s << "#{html_field}"
|
19
|
+
s << "#{html_label}"
|
20
|
+
else
|
21
|
+
s << "#{html_label}"
|
22
|
+
s << "#{html_field}"
|
23
|
+
end
|
24
|
+
s << "#{html_help_text}"
|
25
|
+
s << html_errors.join if html_errors
|
26
|
+
|
27
|
+
s << "</div>"
|
28
|
+
|
29
|
+
s
|
30
|
+
end
|
31
|
+
|
32
|
+
def input_html_attributes(html_attrs:, field_type:, has_errors:)
|
33
|
+
case field_type
|
34
|
+
when "checkbox", "radio"
|
35
|
+
html_attrs["class"] = "form-check-input#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
36
|
+
when "file"
|
37
|
+
html_attrs["class"] = "form-control-file#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
38
|
+
else
|
39
|
+
html_attrs["class"] = "form-control#{" is-invalid" if has_errors} #{html_attrs["class"]}".strip
|
40
|
+
end
|
41
|
+
|
42
|
+
html_attrs
|
43
|
+
end
|
44
|
+
|
45
|
+
def label_html_attributes(html_attrs:, field_type:, has_errors:)
|
46
|
+
if ["checkbox", "radio"].include?(field_type)
|
47
|
+
html_attrs["class"] = "form-check-label #{html_attrs["class"]}".strip
|
48
|
+
end
|
49
|
+
|
50
|
+
html_attrs
|
51
|
+
end
|
52
|
+
|
53
|
+
def form_html_attributes(html_attrs:)
|
54
|
+
html_attrs
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_html_help_text(help_text:, html_attrs:, field_type:)
|
58
|
+
html_attrs["class"] = "form-text #{html_attrs["class"]}".strip
|
59
|
+
|
60
|
+
s = ""
|
61
|
+
s << (html_attrs.empty? ? "<small>" : "<small #{SexyForm.build_html_attr_string(html_attrs)}>")
|
62
|
+
s << "#{help_text}"
|
63
|
+
s << "</small>"
|
64
|
+
s
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_html_error(error:, html_attrs:, field_type:)
|
68
|
+
html_attrs["class"] = "invalid-feedback #{html_attrs["class"]}".strip
|
69
|
+
|
70
|
+
s = ""
|
71
|
+
s << (html_attrs.empty? ? "<div>" : "<div #{SexyForm.build_html_attr_string(html_attrs)}>")
|
72
|
+
s << "#{error}"
|
73
|
+
s << "</div>"
|
74
|
+
s
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module SexyForm
|
2
|
+
module Themes
|
3
|
+
class BulmaHorizontal < BaseTheme
|
4
|
+
|
5
|
+
def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:)
|
6
|
+
s = ""
|
7
|
+
|
8
|
+
wrapper_html_attributes["class"] = "field is-horizontal #{wrapper_html_attributes["class"]}".strip
|
9
|
+
|
10
|
+
attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes)
|
11
|
+
s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}"
|
12
|
+
|
13
|
+
unless ["checkbox", "radio"].include?(field_type) && html_label
|
14
|
+
s << "#{html_label}"
|
15
|
+
end
|
16
|
+
|
17
|
+
s << %Q(<div class="field-body">)
|
18
|
+
s << %Q(<div class="field">)
|
19
|
+
s << %Q(<div class="control">)
|
20
|
+
|
21
|
+
if ["checkbox", "radio"].include?(field_type) && html_label
|
22
|
+
s << html_label.sub("\">", "\">#{html_field} ")
|
23
|
+
else
|
24
|
+
s << "#{html_field}"
|
25
|
+
end
|
26
|
+
|
27
|
+
s << "#{html_help_text}"
|
28
|
+
s << html_errors.join if html_errors
|
29
|
+
|
30
|
+
s << "</div>"
|
31
|
+
s << "</div>"
|
32
|
+
s << "</div>"
|
33
|
+
s << "</div>"
|
34
|
+
|
35
|
+
s
|
36
|
+
end
|
37
|
+
|
38
|
+
def input_html_attributes(html_attrs:, field_type:, has_errors:)
|
39
|
+
if has_errors
|
40
|
+
html_attrs["class"] = "is-danger #{html_attrs["class"]}".strip
|
41
|
+
end
|
42
|
+
|
43
|
+
html_attrs
|
44
|
+
end
|
45
|
+
|
46
|
+
def label_html_attributes(html_attrs:, field_type:, has_errors:)
|
47
|
+
if ["checkbox", "radio"].include?(field_type)
|
48
|
+
html_attrs["class"] = "#{field_type} #{html_attrs["class"]}".strip
|
49
|
+
else
|
50
|
+
html_attrs["class"] = "label is-normal #{html_attrs["class"]}".strip
|
51
|
+
end
|
52
|
+
html_attrs
|
53
|
+
end
|
54
|
+
|
55
|
+
def form_html_attributes(html_attrs:)
|
56
|
+
html_attrs
|
57
|
+
end
|
58
|
+
|
59
|
+
def build_html_help_text(help_text:, html_attrs:, field_type:)
|
60
|
+
html_attrs["class"] = "help #{html_attrs["class"]}".strip
|
61
|
+
|
62
|
+
s = ""
|
63
|
+
s << (html_attrs.empty? ? "<p>" : "<p #{SexyForm.build_html_attr_string(html_attrs)}>")
|
64
|
+
s << "#{help_text}"
|
65
|
+
s << "</p>"
|
66
|
+
s
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_html_error(error:, html_attrs:, field_type:)
|
70
|
+
html_attrs["class"] = "help is-danger #{html_attrs["class"]}".strip
|
71
|
+
|
72
|
+
s = ""
|
73
|
+
s << (html_attrs.empty? ? "<p>" : "<p #{SexyForm.build_html_attr_string(html_attrs)}>")
|
74
|
+
s << "#{error}"
|
75
|
+
s << "</p>"
|
76
|
+
s
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module SexyForm
|
2
|
+
module Themes
|
3
|
+
class BulmaVertical < BaseTheme
|
4
|
+
|
5
|
+
def wrap_field(field_type:, html_field:, html_label:, html_help_text: nil, html_errors: nil, wrapper_html_attributes:)
|
6
|
+
s = ""
|
7
|
+
|
8
|
+
wrapper_html_attributes["class"] = "field #{wrapper_html_attributes["class"]}".strip
|
9
|
+
|
10
|
+
attr_str = SexyForm.build_html_attr_string(wrapper_html_attributes)
|
11
|
+
s << "#{attr_str.empty? ? "<div>" : "<div #{attr_str}>"}"
|
12
|
+
|
13
|
+
if ["checkbox", "radio"].include?(field_type) && html_label
|
14
|
+
s << %Q(<div class="control">)
|
15
|
+
s << html_label.sub("\">", "\">#{html_field} ")
|
16
|
+
else
|
17
|
+
s << "#{html_label}"
|
18
|
+
s << %Q(<div class="control">)
|
19
|
+
s << "#{html_field}"
|
20
|
+
end
|
21
|
+
s << "#{html_help_text}"
|
22
|
+
s << html_errors.join if html_errors
|
23
|
+
s << "</div>"
|
24
|
+
|
25
|
+
s << "</div>"
|
26
|
+
|
27
|
+
s
|
28
|
+
end
|
29
|
+
|
30
|
+
def input_html_attributes(html_attrs:, field_type:, has_errors:)
|
31
|
+
if has_errors
|
32
|
+
html_attrs["class"] = "is-danger #{html_attrs["class"]}".strip
|
33
|
+
end
|
34
|
+
|
35
|
+
html_attrs
|
36
|
+
end
|
37
|
+
|
38
|
+
def label_html_attributes(html_attrs:, field_type:, has_errors:)
|
39
|
+
if ["checkbox", "radio"].include?(field_type)
|
40
|
+
html_attrs["class"] = "#{field_type} #{html_attrs["class"]}".strip
|
41
|
+
else
|
42
|
+
html_attrs["class"] = "label #{html_attrs["class"]}".strip
|
43
|
+
end
|
44
|
+
html_attrs
|
45
|
+
end
|
46
|
+
|
47
|
+
def form_html_attributes(html_attrs:)
|
48
|
+
html_attrs
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_html_help_text(help_text:, html_attrs:, field_type:)
|
52
|
+
html_attrs["class"] = "help #{html_attrs["class"]}".strip
|
53
|
+
|
54
|
+
s = ""
|
55
|
+
s << (html_attrs.empty? ? "<p>" : "<p #{SexyForm.build_html_attr_string(html_attrs)}>")
|
56
|
+
s << "#{help_text}"
|
57
|
+
s << "</p>"
|
58
|
+
s
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_html_error(error:, html_attrs:, field_type:)
|
62
|
+
html_attrs["class"] = "help is-danger #{html_attrs["class"]}".strip
|
63
|
+
|
64
|
+
s = ""
|
65
|
+
s << (html_attrs.empty? ? "<p>" : "<p #{SexyForm.build_html_attr_string(html_attrs)}>")
|
66
|
+
s << "#{error}"
|
67
|
+
s << "</p>"
|
68
|
+
s
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|