govuk_elements_form_builder 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b43d881f552b63310176c72eaa304ed53e5b89de
|
4
|
+
data.tar.gz: 2b0086ffaabcbf31e15311ffee4eddae8ad62cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e94aa32b4bcaefa3020fe6797fcb7eb6acb2ed484bf70deec782908678c53fe21a2c4d9befac3f3d9370631f0f51ee05d883dca1c622ec5298cf9eb5253e0ce4
|
7
|
+
data.tar.gz: 7633c157a26792fdc1ae018b649b16ecf0bfc50b3d505c6afd71a9b0369c86a99d99b961ddd6d302b7ac3b223668e611bce81b88f5189a61d4ce0583adaa6282
|
@@ -30,7 +30,7 @@ module GovukElementsFormBuilder
|
|
30
30
|
options = args.extract_options!
|
31
31
|
|
32
32
|
set_label_classes! options
|
33
|
-
set_field_classes! options
|
33
|
+
set_field_classes! options, attribute
|
34
34
|
|
35
35
|
label = label(attribute, options[:label_options])
|
36
36
|
|
@@ -47,7 +47,7 @@ module GovukElementsFormBuilder
|
|
47
47
|
id: form_group_id(attribute) do
|
48
48
|
content_tag :fieldset, fieldset_options(attribute, options) do
|
49
49
|
safe_join([
|
50
|
-
fieldset_legend(attribute
|
50
|
+
fieldset_legend(attribute),
|
51
51
|
radio_inputs(attribute, options)
|
52
52
|
], "\n")
|
53
53
|
end
|
@@ -60,7 +60,7 @@ module GovukElementsFormBuilder
|
|
60
60
|
id: form_group_id(attributes) do
|
61
61
|
content_tag :fieldset, fieldset_options(attributes, options) do
|
62
62
|
safe_join([
|
63
|
-
fieldset_legend(legend_key
|
63
|
+
fieldset_legend(legend_key),
|
64
64
|
check_box_inputs(attributes)
|
65
65
|
], "\n")
|
66
66
|
end
|
@@ -72,7 +72,7 @@ module GovukElementsFormBuilder
|
|
72
72
|
content_tag :div, class: form_group_classes(method), id: form_group_id(method) do
|
73
73
|
|
74
74
|
html_options = args.extract_options!
|
75
|
-
set_field_classes! html_options
|
75
|
+
set_field_classes! html_options, method
|
76
76
|
|
77
77
|
label = label(method, class: "form-label")
|
78
78
|
add_hint :label, label, method
|
@@ -84,36 +84,47 @@ module GovukElementsFormBuilder
|
|
84
84
|
|
85
85
|
private
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
options ||= {}
|
99
|
-
options.merge!(
|
100
|
-
merge_attributes(options, default: {class: 'form-control'})
|
101
|
-
)
|
87
|
+
def set_field_classes! options, attribute
|
88
|
+
text_field_class = "form-control"
|
89
|
+
text_field_class = [text_field_class, 'form-control-error'] if error_for? attribute
|
90
|
+
options[:class] = case options[:class]
|
91
|
+
when String
|
92
|
+
[text_field_class, options[:class]]
|
93
|
+
when Array
|
94
|
+
options[:class].unshift text_field_class
|
95
|
+
else
|
96
|
+
options[:class] = text_field_class
|
97
|
+
end
|
102
98
|
end
|
103
99
|
|
104
100
|
def set_label_classes! options
|
105
|
-
|
106
|
-
|
107
|
-
options[:label_options].
|
108
|
-
|
109
|
-
|
101
|
+
text_field_class = "form-label"
|
102
|
+
|
103
|
+
if options.present? && options[:label_options].present?
|
104
|
+
options[:label_options][:class] = case options[:label_options][:class]
|
105
|
+
when String
|
106
|
+
[text_field_class, options[:label_options][:class]]
|
107
|
+
when Array
|
108
|
+
options[:label_options][:class].unshift text_field_class
|
109
|
+
else
|
110
|
+
options[:label_options][:class] = text_field_class
|
111
|
+
end
|
112
|
+
else
|
113
|
+
options ||= {}
|
114
|
+
options[:label_options] ||= {}
|
115
|
+
options[:label_options][:class] = text_field_class
|
116
|
+
end
|
117
|
+
|
110
118
|
end
|
111
119
|
|
112
120
|
def check_box_inputs attributes
|
113
121
|
attributes.map do |attribute|
|
114
|
-
|
115
|
-
|
116
|
-
|
122
|
+
input = check_box(attribute)
|
123
|
+
label = label(attribute) do |tag|
|
124
|
+
localized_label("#{attribute}")
|
125
|
+
end
|
126
|
+
content_tag :div, class: "multiple-choice" do
|
127
|
+
input + label
|
117
128
|
end
|
118
129
|
end
|
119
130
|
end
|
@@ -122,26 +133,27 @@ module GovukElementsFormBuilder
|
|
122
133
|
choices = options[:choices] || [ :yes, :no ]
|
123
134
|
choices.map do |choice|
|
124
135
|
value = choice.send(options[:value_method] || :to_s)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
136
|
+
input = radio_button(attribute, value)
|
137
|
+
label = label(attribute, value: value) do |tag|
|
138
|
+
text = if options.has_key? :text_method
|
139
|
+
choice.send(options[:text_method])
|
140
|
+
else
|
141
|
+
localized_label("#{attribute}.#{choice}")
|
142
|
+
end
|
143
|
+
text
|
144
|
+
end
|
145
|
+
content_tag :div, class: "multiple-choice" do
|
146
|
+
input + label
|
135
147
|
end
|
136
148
|
end
|
137
149
|
end
|
138
150
|
|
139
|
-
def fieldset_legend attribute
|
151
|
+
def fieldset_legend attribute
|
140
152
|
legend = content_tag(:legend) do
|
141
153
|
tags = [content_tag(
|
142
154
|
:span,
|
143
155
|
fieldset_text(attribute),
|
144
|
-
|
156
|
+
class: 'form-label-bold'
|
145
157
|
)]
|
146
158
|
|
147
159
|
if error_for? attribute
|
@@ -219,7 +231,7 @@ module GovukElementsFormBuilder
|
|
219
231
|
def form_group_classes attributes
|
220
232
|
attributes = [attributes] if !attributes.respond_to? :count
|
221
233
|
classes = 'form-group'
|
222
|
-
classes += ' error' if attributes.find { |a| error_for? a }
|
234
|
+
classes += ' form-group-error' if attributes.find { |a| error_for? a }
|
223
235
|
classes
|
224
236
|
end
|
225
237
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_elements_form_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alistair Laing
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -25,6 +25,34 @@ dependencies:
|
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '4.2'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: govuk_frontend_toolkit
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 6.0.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 6.0.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: govuk_elements_rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.0.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 3.0.0
|
28
56
|
- !ruby/object:Gem::Dependency
|
29
57
|
name: sqlite3
|
30
58
|
requirement: !ruby/object:Gem::Requirement
|