govuk_design_system_formbuilder 1.2.7 → 2.0.0b1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/govuk_design_system_formbuilder/builder.rb +147 -72
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +9 -9
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +4 -3
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +10 -10
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +12 -12
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +6 -2
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +7 -3
- data/lib/govuk_design_system_formbuilder/elements/date.rb +8 -8
- data/lib/govuk_design_system_formbuilder/elements/file.rb +7 -7
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +35 -8
- data/lib/govuk_design_system_formbuilder/elements/label.rb +6 -2
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +14 -14
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +9 -1
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +13 -5
- data/lib/govuk_design_system_formbuilder/elements/select.rb +11 -11
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +11 -11
- data/lib/govuk_design_system_formbuilder/traits/collection_item.rb +1 -1
- data/lib/govuk_design_system_formbuilder/traits/hint.rb +15 -2
- data/lib/govuk_design_system_formbuilder/traits/input.rb +8 -8
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52cc4abc62b3ac208e8fe2befb527b6deda60868d2094a3172d907bc0ce82654
|
4
|
+
data.tar.gz: fb0c810a65f025e226fe4dc0cee0c5b42b3b7baa499b032d6f88d4ec2fac9d54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 996a9f979a4eab0a16499f81cf39fdcfbd0c641dd5d2944c52be697cd6f1f8870b75c6fd4b498d3769265fa39168f7baefe36bb53255bc50a9bfcb82f06bd641
|
7
|
+
data.tar.gz: ef2f8f3eaba7ea21b2ae18a7a4ba8c181981164f36917d082ff5f2545896df17c6b27c9acab09621d3e5453013d9e5747e5f838b54bc2f2e68aed585980190d9
|
@@ -5,7 +5,11 @@ module GOVUKDesignSystemFormBuilder
|
|
5
5
|
# Generates a input of type +text+
|
6
6
|
#
|
7
7
|
# @param attribute_name [Symbol] The name of the attribute
|
8
|
-
# @param
|
8
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
9
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
10
|
+
# @option hint text [String] the hint text
|
11
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
12
|
+
#
|
9
13
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
10
14
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
11
15
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -17,7 +21,9 @@ module GOVUKDesignSystemFormBuilder
|
|
17
21
|
# @option caption text [String] the caption text
|
18
22
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
19
23
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
20
|
-
# @param
|
24
|
+
# @param form_group [Hash] configures the form group
|
25
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
26
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
21
27
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
22
28
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
23
29
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -26,7 +32,7 @@ module GOVUKDesignSystemFormBuilder
|
|
26
32
|
# @example A required full name field with a placeholder
|
27
33
|
# = f.govuk_text_field :name,
|
28
34
|
# label: { text: 'Full name' },
|
29
|
-
#
|
35
|
+
# hint: { text: 'It says it on your birth certificate' },
|
30
36
|
# required: true,
|
31
37
|
# placeholder: 'Ralph Wiggum'
|
32
38
|
#
|
@@ -41,14 +47,17 @@ module GOVUKDesignSystemFormBuilder
|
|
41
47
|
# = f.govuk_text_field :callsign,
|
42
48
|
# label: -> { tag.h3('Call-sign') }
|
43
49
|
#
|
44
|
-
def govuk_text_field(attribute_name,
|
45
|
-
Elements::Inputs::Text.new(self, object_name, attribute_name,
|
50
|
+
def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **args, &block)
|
51
|
+
Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **args, &block).html
|
46
52
|
end
|
47
53
|
|
48
54
|
# Generates a input of type +tel+
|
49
55
|
#
|
50
56
|
# @param attribute_name [Symbol] The name of the attribute
|
51
|
-
# @param
|
57
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
58
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
59
|
+
# @option hint text [String] the hint text
|
60
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
52
61
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
53
62
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
54
63
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -60,7 +69,9 @@ module GOVUKDesignSystemFormBuilder
|
|
60
69
|
# @option caption text [String] the caption text
|
61
70
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
62
71
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
63
|
-
# @param
|
72
|
+
# @param form_group [Hash] configures the form group
|
73
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
74
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
64
75
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
65
76
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
66
77
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -70,7 +81,7 @@ module GOVUKDesignSystemFormBuilder
|
|
70
81
|
# @example A required phone number field with a placeholder
|
71
82
|
# = f.govuk_phone_field :phone_number,
|
72
83
|
# label: { text: 'UK telephone number' },
|
73
|
-
#
|
84
|
+
# hint: { text: 'Include the dialling code' },
|
74
85
|
# required: true,
|
75
86
|
# placeholder: '0123 456 789'
|
76
87
|
#
|
@@ -85,14 +96,17 @@ module GOVUKDesignSystemFormBuilder
|
|
85
96
|
# = f.govuk_phone_field :work_number,
|
86
97
|
# label: -> { tag.h3('Work number') }
|
87
98
|
#
|
88
|
-
def govuk_phone_field(attribute_name,
|
89
|
-
Elements::Inputs::Phone.new(self, object_name, attribute_name,
|
99
|
+
def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **args, &block)
|
100
|
+
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **args, &block).html
|
90
101
|
end
|
91
102
|
|
92
103
|
# Generates a input of type +email+
|
93
104
|
#
|
94
105
|
# @param attribute_name [Symbol] The name of the attribute
|
95
|
-
# @param
|
106
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
107
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
108
|
+
# @option hint text [String] the hint text
|
109
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
96
110
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
97
111
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
98
112
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -104,7 +118,9 @@ module GOVUKDesignSystemFormBuilder
|
|
104
118
|
# @option caption text [String] the caption text
|
105
119
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
106
120
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
107
|
-
# @param
|
121
|
+
# @param form_group [Hash] configures the form group
|
122
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
123
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
108
124
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
109
125
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
110
126
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -127,14 +143,17 @@ module GOVUKDesignSystemFormBuilder
|
|
127
143
|
# = f.govuk_email_field :personal_email,
|
128
144
|
# label: -> { tag.h3('Personal email address') }
|
129
145
|
#
|
130
|
-
def govuk_email_field(attribute_name,
|
131
|
-
Elements::Inputs::Email.new(self, object_name, attribute_name,
|
146
|
+
def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **args, &block)
|
147
|
+
Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **args, &block).html
|
132
148
|
end
|
133
149
|
|
134
150
|
# Generates a input of type +password+
|
135
151
|
#
|
136
152
|
# @param attribute_name [Symbol] The name of the attribute
|
137
|
-
# @param
|
153
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
154
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
155
|
+
# @option hint text [String] the hint text
|
156
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
138
157
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
139
158
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
140
159
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -146,7 +165,9 @@ module GOVUKDesignSystemFormBuilder
|
|
146
165
|
# @option caption text [String] the caption text
|
147
166
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
148
167
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
149
|
-
# @param
|
168
|
+
# @param form_group [Hash] configures the form group
|
169
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
170
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
150
171
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
151
172
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
152
173
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -168,14 +189,17 @@ module GOVUKDesignSystemFormBuilder
|
|
168
189
|
# = f.govuk_password_field :passcode,
|
169
190
|
# label: -> { tag.h3('What is your secret pass code?') }
|
170
191
|
#
|
171
|
-
def govuk_password_field(attribute_name,
|
172
|
-
Elements::Inputs::Password.new(self, object_name, attribute_name,
|
192
|
+
def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, form_group: {}, caption: {}, **args, &block)
|
193
|
+
Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **args, &block).html
|
173
194
|
end
|
174
195
|
|
175
196
|
# Generates a input of type +url+
|
176
197
|
#
|
177
198
|
# @param attribute_name [Symbol] The name of the attribute
|
178
|
-
# @param
|
199
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
200
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
201
|
+
# @option hint text [String] the hint text
|
202
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
179
203
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
180
204
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
181
205
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -187,7 +211,9 @@ module GOVUKDesignSystemFormBuilder
|
|
187
211
|
# @option caption text [String] the caption text
|
188
212
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
189
213
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
190
|
-
# @param
|
214
|
+
# @param form_group [Hash] configures the form group
|
215
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
216
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
191
217
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
192
218
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
193
219
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -210,14 +236,17 @@ module GOVUKDesignSystemFormBuilder
|
|
210
236
|
# = f.govuk_url_field :work_website,
|
211
237
|
# label: -> { tag.h3("Enter your company's website") }
|
212
238
|
#
|
213
|
-
def govuk_url_field(attribute_name,
|
214
|
-
Elements::Inputs::URL.new(self, object_name, attribute_name,
|
239
|
+
def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **args, &block)
|
240
|
+
Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **args, &block).html
|
215
241
|
end
|
216
242
|
|
217
243
|
# Generates a input of type +number+
|
218
244
|
#
|
219
245
|
# @param attribute_name [Symbol] The name of the attribute
|
220
|
-
# @param
|
246
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
247
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
248
|
+
# @option hint text [String] the hint text
|
249
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
221
250
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
222
251
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
223
252
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -229,7 +258,9 @@ module GOVUKDesignSystemFormBuilder
|
|
229
258
|
# @option caption text [String] the caption text
|
230
259
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
231
260
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
232
|
-
# @param
|
261
|
+
# @param form_group [Hash] configures the form group
|
262
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
263
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
233
264
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
234
265
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
235
266
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -255,8 +286,8 @@ module GOVUKDesignSystemFormBuilder
|
|
255
286
|
# = f.govuk_url_field :personal_best_over_100m,
|
256
287
|
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
|
257
288
|
#
|
258
|
-
def govuk_number_field(attribute_name,
|
259
|
-
Elements::Inputs::Number.new(self, object_name, attribute_name,
|
289
|
+
def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **args, &block)
|
290
|
+
Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **args, &block).html
|
260
291
|
end
|
261
292
|
|
262
293
|
# Generates a +textarea+ element with a label, optional hint. Also offers
|
@@ -264,7 +295,10 @@ module GOVUKDesignSystemFormBuilder
|
|
264
295
|
# automatically
|
265
296
|
#
|
266
297
|
# @param attribute_name [Symbol] The name of the attribute
|
267
|
-
# @param
|
298
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
299
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
300
|
+
# @option hint text [String] the hint text
|
301
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
268
302
|
# @param label [Hash,Proc] configures or sets the associated label content
|
269
303
|
# @option label text [String] the label text
|
270
304
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
@@ -278,7 +312,9 @@ module GOVUKDesignSystemFormBuilder
|
|
278
312
|
# @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
|
279
313
|
# @param rows [Integer] sets the initial number of rows
|
280
314
|
# @option args [Hash] args additional arguments are applied as attributes to the +textarea+ element
|
281
|
-
# @param
|
315
|
+
# @param form_group [Hash] configures the form group
|
316
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
317
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
282
318
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
283
319
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
284
320
|
# @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
|
@@ -304,8 +340,8 @@ module GOVUKDesignSystemFormBuilder
|
|
304
340
|
# = f.govuk_text_area :instructions,
|
305
341
|
# label: -> { tag.h3("How do you set it up?") }
|
306
342
|
#
|
307
|
-
def govuk_text_area(attribute_name,
|
308
|
-
Elements::TextArea.new(self, object_name, attribute_name,
|
343
|
+
def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **args, &block)
|
344
|
+
Elements::TextArea.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, form_group: form_group, **args, &block).html
|
309
345
|
end
|
310
346
|
|
311
347
|
# Generates a +select+ element containing +option+ for each member in the provided collection
|
@@ -314,14 +350,19 @@ module GOVUKDesignSystemFormBuilder
|
|
314
350
|
# @param collection [Enumerable<Object>] Options to be added to the +select+ element
|
315
351
|
# @param value_method [Symbol] The method called against each member of the collection to provide the value
|
316
352
|
# @param text_method [Symbol] The method called against each member of the collection to provide the text
|
317
|
-
# @param
|
353
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
354
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
355
|
+
# @option hint text [String] the hint text
|
356
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
318
357
|
# @option label text [String] the label text
|
319
358
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
320
359
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
321
360
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
322
361
|
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
323
362
|
# @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
|
324
|
-
# @param
|
363
|
+
# @param form_group [Hash] configures the form group
|
364
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
365
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
325
366
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
326
367
|
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
327
368
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -331,7 +372,7 @@ module GOVUKDesignSystemFormBuilder
|
|
331
372
|
# @grades,
|
332
373
|
# :id,
|
333
374
|
# :name,
|
334
|
-
#
|
375
|
+
# hint: { text: "If you took the test more than once enter your highest grade" }
|
335
376
|
#
|
336
377
|
# @example A select box with injected content
|
337
378
|
# = f.govuk_collection_select(:favourite_colour, @colours, :id, :name) do
|
@@ -343,7 +384,7 @@ module GOVUKDesignSystemFormBuilder
|
|
343
384
|
# = f.govuk_collection_select(:team, @teams, :id, :name) do
|
344
385
|
# label: -> { tag.h3("Which team did you represent?") }
|
345
386
|
#
|
346
|
-
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {},
|
387
|
+
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint: {}, label: {}, caption: {}, form_group: {}, &block)
|
347
388
|
Elements::Select.new(
|
348
389
|
self,
|
349
390
|
object_name,
|
@@ -351,12 +392,12 @@ module GOVUKDesignSystemFormBuilder
|
|
351
392
|
collection,
|
352
393
|
value_method: value_method,
|
353
394
|
text_method: text_method,
|
354
|
-
|
395
|
+
hint: hint,
|
355
396
|
label: label,
|
356
397
|
caption: caption,
|
357
398
|
options: options,
|
358
399
|
html_options: html_options,
|
359
|
-
|
400
|
+
form_group: form_group,
|
360
401
|
&block
|
361
402
|
).html
|
362
403
|
end
|
@@ -380,7 +421,10 @@ module GOVUKDesignSystemFormBuilder
|
|
380
421
|
# @param hint_method [Symbol, Proc, nil] The method called against each member of the collection to provide the hint text.
|
381
422
|
# When a +Proc+ is provided it must take a single argument that is a single member of the collection.
|
382
423
|
# When a +nil+ value is provided the hint text will be retrieved from the locale. This is the default and param can be omitted.
|
383
|
-
# @param
|
424
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
425
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
426
|
+
# @option hint text [String] the hint text
|
427
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
384
428
|
# @param legend [Hash,Proc] options for configuring the legend
|
385
429
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
386
430
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
@@ -408,7 +452,7 @@ module GOVUKDesignSystemFormBuilder
|
|
408
452
|
# ->(option) { option.name.upcase },
|
409
453
|
# :description,
|
410
454
|
# legend: { text: 'Pick your favourite colour', size: 'm' },
|
411
|
-
#
|
455
|
+
# hint: { text: 'If you cannot find the exact match choose something close' },
|
412
456
|
# inline: false
|
413
457
|
#
|
414
458
|
# @example A collection of radio buttons for grades with injected content
|
@@ -427,7 +471,7 @@ module GOVUKDesignSystemFormBuilder
|
|
427
471
|
# :name,
|
428
472
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
429
473
|
#
|
430
|
-
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil,
|
474
|
+
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, form_group: {}, &block)
|
431
475
|
Elements::Radios::Collection.new(
|
432
476
|
self,
|
433
477
|
object_name,
|
@@ -436,14 +480,14 @@ module GOVUKDesignSystemFormBuilder
|
|
436
480
|
value_method: value_method,
|
437
481
|
text_method: text_method,
|
438
482
|
hint_method: hint_method,
|
439
|
-
|
483
|
+
hint: hint,
|
440
484
|
legend: legend,
|
441
485
|
caption: caption,
|
442
486
|
inline: inline,
|
443
487
|
small: small,
|
444
488
|
bold_labels: bold_labels,
|
445
489
|
classes: classes,
|
446
|
-
|
490
|
+
form_group: form_group,
|
447
491
|
&block
|
448
492
|
).html
|
449
493
|
end
|
@@ -456,7 +500,10 @@ module GOVUKDesignSystemFormBuilder
|
|
456
500
|
# is set to +link_errors: true+
|
457
501
|
#
|
458
502
|
# @param attribute_name [Symbol] The name of the attribute
|
459
|
-
# @param
|
503
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
504
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
505
|
+
# @option hint text [String] the hint text
|
506
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
460
507
|
# @param legend [Hash,Proc] options for configuring the legend
|
461
508
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
462
509
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
@@ -467,7 +514,9 @@ module GOVUKDesignSystemFormBuilder
|
|
467
514
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
468
515
|
# @option caption text [String] the caption text
|
469
516
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
470
|
-
# @param
|
517
|
+
# @param form_group [Hash] configures the form group
|
518
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
519
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
471
520
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
472
521
|
# @param classes [Array,String] Classes to add to the radio button container.
|
473
522
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
@@ -491,15 +540,18 @@ module GOVUKDesignSystemFormBuilder
|
|
491
540
|
# = f.govuk_radio_button :burger_id, :regular, label: { text: 'Hamburger' }, link_errors: true
|
492
541
|
# = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
|
493
542
|
#
|
494
|
-
def govuk_radio_buttons_fieldset(attribute_name,
|
495
|
-
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name,
|
543
|
+
def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, classes: nil, form_group: {}, &block)
|
544
|
+
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, inline: inline, small: small, classes: classes, form_group: form_group, &block).html
|
496
545
|
end
|
497
546
|
|
498
547
|
# Generates a radio button
|
499
548
|
#
|
500
549
|
# @note This should only be used from within a {#govuk_radio_buttons_fieldset}
|
501
550
|
# @param attribute_name [Symbol] The name of the attribute
|
502
|
-
# @param
|
551
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
552
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
553
|
+
# @option hint text [String] the hint text
|
554
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
503
555
|
# @option legend text [String] the fieldset legend's text content
|
504
556
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
505
557
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
@@ -517,8 +569,8 @@ module GOVUKDesignSystemFormBuilder
|
|
517
569
|
# = f.govuk_radio_buttons_fieldset :favourite_colour do
|
518
570
|
# = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
|
519
571
|
#
|
520
|
-
def govuk_radio_button(attribute_name, value,
|
521
|
-
Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value,
|
572
|
+
def govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, &block)
|
573
|
+
Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, &block).html
|
522
574
|
end
|
523
575
|
|
524
576
|
# Inserts a text divider into a list of radio buttons
|
@@ -541,7 +593,10 @@ module GOVUKDesignSystemFormBuilder
|
|
541
593
|
# @param text_method [Symbol] The method called against each member of the collection to provide the label text
|
542
594
|
# @param hint_method [Symbol, Proc] The method called against each member of the collection to provide the hint text.
|
543
595
|
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
544
|
-
# @param
|
596
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
597
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
598
|
+
# @option hint text [String] the hint text
|
599
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
545
600
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
546
601
|
# @param classes [Array,String] Classes to add to the checkbox container.
|
547
602
|
# @param legend [Hash,Proc] options for configuring the legend
|
@@ -552,7 +607,9 @@ module GOVUKDesignSystemFormBuilder
|
|
552
607
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
553
608
|
# @option caption text [String] the caption text
|
554
609
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
555
|
-
# @param
|
610
|
+
# @param form_group [Hash] configures the form group
|
611
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
612
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
556
613
|
# @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
|
557
614
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
558
615
|
#
|
@@ -569,7 +626,7 @@ module GOVUKDesignSystemFormBuilder
|
|
569
626
|
# :name,
|
570
627
|
# :description,
|
571
628
|
# legend: { text: 'What do you want in your sandwich?', size: 'm' },
|
572
|
-
#
|
629
|
+
# hint: { text: "If it isn't listed here, tough luck" },
|
573
630
|
# inline: false,
|
574
631
|
# classes: 'app-overflow-scroll',
|
575
632
|
#
|
@@ -589,7 +646,7 @@ module GOVUKDesignSystemFormBuilder
|
|
589
646
|
# :name,
|
590
647
|
# legend: -> { tag.h3('What kind of sandwich do you want?') }
|
591
648
|
#
|
592
|
-
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil,
|
649
|
+
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false, classes: nil, form_group: {}, &block)
|
593
650
|
Elements::CheckBoxes::Collection.new(
|
594
651
|
self,
|
595
652
|
object_name,
|
@@ -598,12 +655,12 @@ module GOVUKDesignSystemFormBuilder
|
|
598
655
|
value_method: value_method,
|
599
656
|
text_method: text_method,
|
600
657
|
hint_method: hint_method,
|
601
|
-
|
658
|
+
hint: hint,
|
602
659
|
legend: legend,
|
603
660
|
caption: caption,
|
604
661
|
small: small,
|
605
662
|
classes: classes,
|
606
|
-
|
663
|
+
form_group: form_group,
|
607
664
|
&block
|
608
665
|
).html
|
609
666
|
end
|
@@ -614,7 +671,10 @@ module GOVUKDesignSystemFormBuilder
|
|
614
671
|
# is set to +link_errors: true+
|
615
672
|
#
|
616
673
|
# @param attribute_name [Symbol] The name of the attribute
|
617
|
-
# @param
|
674
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
675
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
676
|
+
# @option hint text [String] the hint text
|
677
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
618
678
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
619
679
|
# @param legend [Hash,Proc] options for configuring the legend
|
620
680
|
# @option legend text [String] the fieldset legend's text content
|
@@ -625,7 +685,9 @@ module GOVUKDesignSystemFormBuilder
|
|
625
685
|
# @option caption text [String] the caption text
|
626
686
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
627
687
|
# @param classes [Array,String] Classes to add to the checkbox container.
|
628
|
-
# @param
|
688
|
+
# @param form_group [Hash] configures the form group
|
689
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
690
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
629
691
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
630
692
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
631
693
|
#
|
@@ -639,17 +701,17 @@ module GOVUKDesignSystemFormBuilder
|
|
639
701
|
# = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
|
640
702
|
# = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
|
641
703
|
#
|
642
|
-
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {},
|
704
|
+
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, classes: nil, form_group: {}, &block)
|
643
705
|
Containers::CheckBoxesFieldset.new(
|
644
706
|
self,
|
645
707
|
object_name,
|
646
708
|
attribute_name,
|
647
|
-
|
709
|
+
hint: hint,
|
648
710
|
legend: legend,
|
649
711
|
caption: caption,
|
650
712
|
small: small,
|
651
713
|
classes: classes,
|
652
|
-
|
714
|
+
form_group: form_group,
|
653
715
|
&block
|
654
716
|
).html
|
655
717
|
end
|
@@ -658,7 +720,10 @@ module GOVUKDesignSystemFormBuilder
|
|
658
720
|
#
|
659
721
|
# @param attribute_name [Symbol] The name of the attribute
|
660
722
|
# @param value [Boolean,String,Symbol,Integer] The value of the checkbox when it is checked
|
661
|
-
# @param
|
723
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
724
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
725
|
+
# @option hint text [String] the hint text
|
726
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
662
727
|
# @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
|
663
728
|
# @option label text [String] the label text
|
664
729
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
@@ -674,15 +739,15 @@ module GOVUKDesignSystemFormBuilder
|
|
674
739
|
# multiple: false,
|
675
740
|
# link_errors: true,
|
676
741
|
# label: { text: 'Do you agree with our terms and conditions?' },
|
677
|
-
#
|
742
|
+
# hint: { text: 'You will not be able to proceed unless you do' }
|
678
743
|
#
|
679
|
-
def govuk_check_box(attribute_name, value,
|
744
|
+
def govuk_check_box(attribute_name, value, hint: {}, label: {}, link_errors: false, multiple: true, &block)
|
680
745
|
Elements::CheckBoxes::FieldsetCheckBox.new(
|
681
746
|
self,
|
682
747
|
object_name,
|
683
748
|
attribute_name,
|
684
749
|
value,
|
685
|
-
|
750
|
+
hint: hint,
|
686
751
|
label: label,
|
687
752
|
link_errors: link_errors,
|
688
753
|
multiple: multiple,
|
@@ -726,7 +791,10 @@ module GOVUKDesignSystemFormBuilder
|
|
726
791
|
# of {https://bugs.ruby-lang.org/issues/5988 this} bug, so incorrect dates like +2019-09-31+ will
|
727
792
|
# be 'rounded' up to +2019-10-01+.
|
728
793
|
# @param attribute_name [Symbol] The name of the attribute
|
729
|
-
# @param
|
794
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
795
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
796
|
+
# @option hint text [String] the hint text
|
797
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
730
798
|
# @param legend [Hash,Proc] options for configuring the legend
|
731
799
|
# @option legend text [String] the fieldset legend's text content
|
732
800
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
@@ -736,7 +804,9 @@ module GOVUKDesignSystemFormBuilder
|
|
736
804
|
# @option caption text [String] the caption text
|
737
805
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
738
806
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
739
|
-
# @param
|
807
|
+
# @param form_group [Hash] configures the form group
|
808
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
809
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
740
810
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
741
811
|
# @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
|
742
812
|
# will be added to the inputs
|
@@ -748,7 +818,7 @@ module GOVUKDesignSystemFormBuilder
|
|
748
818
|
# @example A regular date input with a legend, hint and injected content
|
749
819
|
# = f.govuk_date_field :starts_on,
|
750
820
|
# legend: { 'When does your event start?' },
|
751
|
-
#
|
821
|
+
# hint: { text: 'Leave this field blank if you don't know exactly' } do
|
752
822
|
#
|
753
823
|
# p.govuk-inset-text
|
754
824
|
# | If you don't fill this in you won't be eligable for a refund
|
@@ -756,8 +826,8 @@ module GOVUKDesignSystemFormBuilder
|
|
756
826
|
# @example A date input with legend supplied as a proc
|
757
827
|
# = f.govuk_date_field :finishes_on,
|
758
828
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
759
|
-
def govuk_date_field(attribute_name,
|
760
|
-
Elements::Date.new(self, object_name, attribute_name,
|
829
|
+
def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, &block)
|
830
|
+
Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group: form_group, &block).html
|
761
831
|
end
|
762
832
|
|
763
833
|
# Generates a summary of errors in the form, each linking to the corresponding
|
@@ -813,9 +883,14 @@ module GOVUKDesignSystemFormBuilder
|
|
813
883
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
814
884
|
# @option caption text [String] the caption text
|
815
885
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
816
|
-
# @param
|
886
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
887
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
888
|
+
# @option hint text [String] the hint text
|
889
|
+
# @option hint args [Hash] additional arguments are applied as attributes to the hint
|
817
890
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
818
|
-
# @param
|
891
|
+
# @param form_group [Hash] configures the form group
|
892
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
893
|
+
# @option form_group args [Hash] additional attributes added to the form group
|
819
894
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
820
895
|
#
|
821
896
|
# @example A photo upload field with file type specifier and injected content
|
@@ -834,8 +909,8 @@ module GOVUKDesignSystemFormBuilder
|
|
834
909
|
# @note Remember to set +multipart: true+ when creating a form with file
|
835
910
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
836
911
|
# the Rails documentation} for more information
|
837
|
-
def govuk_file_field(attribute_name, label: {}, caption: {},
|
838
|
-
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption,
|
912
|
+
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **args, &block)
|
913
|
+
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **args, &block).html
|
839
914
|
end
|
840
915
|
end
|
841
916
|
end
|