govuk_design_system_formbuilder 1.2.1 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/govuk_design_system_formbuilder.rb +4 -0
- data/lib/govuk_design_system_formbuilder/builder.rb +49 -29
- data/lib/govuk_design_system_formbuilder/containers/character_count.rb +8 -7
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +18 -10
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +18 -9
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +15 -55
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +18 -10
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +19 -10
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +22 -11
- data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +3 -3
- data/lib/govuk_design_system_formbuilder/elements/caption.rb +8 -6
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +21 -12
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +2 -2
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +16 -12
- data/lib/govuk_design_system_formbuilder/elements/date.rb +48 -41
- data/lib/govuk_design_system_formbuilder/elements/error_message.rb +3 -3
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +15 -15
- data/lib/govuk_design_system_formbuilder/elements/file.rb +11 -10
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +13 -13
- data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/label.rb +31 -23
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +79 -0
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +23 -14
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +13 -3
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +7 -3
- data/lib/govuk_design_system_formbuilder/elements/select.rb +24 -19
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +14 -6
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +29 -23
- data/lib/govuk_design_system_formbuilder/traits/input.rb +9 -8
- data/lib/govuk_design_system_formbuilder/traits/label.rb +2 -2
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c59892549c7150380bda02c9c078026fee857d2e8edacf90e7c4ca4f9be3613f
|
4
|
+
data.tar.gz: 70687f4b813f7b61aa4312e8a7d59ae883cfa4c1bd3d1b3e4a1318b3354d23b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f868193dc418ed5cebefad1456918b95be96108001b68ddedd523e7df151544e49691f675615ae9617e6a05e35891e7790ea7624cdf50b84a98811162b86660
|
7
|
+
data.tar.gz: c7183ad3f84bef8c71d4f303a4c3637f725b7a851732c777774e301178a24ebaac2f971c26e4ca4c70a34c2829e3f94f431c419e752ba535062be941d8fbc1c2
|
data/README.md
CHANGED
@@ -7,10 +7,10 @@
|
|
7
7
|
[](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/test_coverage)
|
8
8
|
[](https://dependabot.com)
|
9
9
|
[](https://github.com/DFE-Digital/govuk_design_system_formbuilder/blob/master/LICENSE)
|
10
|
-
[](https://design-system.service.gov.uk)
|
11
11
|
|
12
12
|
This gem provides a easy-to-use form builder that generates forms that are
|
13
|
-
fully-compliant with version 3.
|
13
|
+
fully-compliant with version 3.8.0 of the [GOV.UK Design System](https://design-system.service.gov.uk/),
|
14
14
|
minimising the amount of markup you need to write.
|
15
15
|
|
16
16
|
In addition to the basic markup, the more-advanced functionality of the Design
|
@@ -14,6 +14,9 @@ module GOVUKDesignSystemFormBuilder
|
|
14
14
|
# * +:brand+ sets the value used to prefix all classes, used to allow the
|
15
15
|
# builder to be branded for alternative (similar) design systems.
|
16
16
|
#
|
17
|
+
# * +:default_caption_size+ controls the default size of caption text.
|
18
|
+
# Can be either +xl+, +l+ or +m+.
|
19
|
+
#
|
17
20
|
# * +:default_legend_size+ controls the default size of legend text.
|
18
21
|
# Can be either +xl+, +l+, +m+ or +s+.
|
19
22
|
#
|
@@ -45,6 +48,7 @@ module GOVUKDesignSystemFormBuilder
|
|
45
48
|
|
46
49
|
default_legend_size: 'm',
|
47
50
|
default_legend_tag: 'h1',
|
51
|
+
default_caption_size: 'm',
|
48
52
|
default_submit_button_text: 'Continue',
|
49
53
|
default_radio_divider_text: 'or',
|
50
54
|
default_error_summary_title: 'There is a problem',
|
@@ -17,6 +17,7 @@ module GOVUKDesignSystemFormBuilder
|
|
17
17
|
# @option caption text [String] the caption text
|
18
18
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
19
19
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
20
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
20
21
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
21
22
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
22
23
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -40,8 +41,8 @@ module GOVUKDesignSystemFormBuilder
|
|
40
41
|
# = f.govuk_text_field :callsign,
|
41
42
|
# label: -> { tag.h3('Call-sign') }
|
42
43
|
#
|
43
|
-
def govuk_text_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
44
|
-
Elements::Inputs::Text.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
44
|
+
def govuk_text_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
45
|
+
Elements::Inputs::Text.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
45
46
|
end
|
46
47
|
|
47
48
|
# Generates a input of type +tel+
|
@@ -59,6 +60,7 @@ module GOVUKDesignSystemFormBuilder
|
|
59
60
|
# @option caption text [String] the caption text
|
60
61
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
61
62
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
63
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
62
64
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
63
65
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
64
66
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -83,8 +85,8 @@ module GOVUKDesignSystemFormBuilder
|
|
83
85
|
# = f.govuk_phone_field :work_number,
|
84
86
|
# label: -> { tag.h3('Work number') }
|
85
87
|
#
|
86
|
-
def govuk_phone_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
87
|
-
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
88
|
+
def govuk_phone_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
89
|
+
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
88
90
|
end
|
89
91
|
|
90
92
|
# Generates a input of type +email+
|
@@ -102,6 +104,7 @@ module GOVUKDesignSystemFormBuilder
|
|
102
104
|
# @option caption text [String] the caption text
|
103
105
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
104
106
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
107
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
105
108
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
106
109
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
107
110
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -124,8 +127,8 @@ module GOVUKDesignSystemFormBuilder
|
|
124
127
|
# = f.govuk_email_field :personal_email,
|
125
128
|
# label: -> { tag.h3('Personal email address') }
|
126
129
|
#
|
127
|
-
def govuk_email_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
128
|
-
Elements::Inputs::Email.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
130
|
+
def govuk_email_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
131
|
+
Elements::Inputs::Email.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
129
132
|
end
|
130
133
|
|
131
134
|
# Generates a input of type +password+
|
@@ -143,6 +146,7 @@ module GOVUKDesignSystemFormBuilder
|
|
143
146
|
# @option caption text [String] the caption text
|
144
147
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
145
148
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
149
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
146
150
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
147
151
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
148
152
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -164,8 +168,8 @@ module GOVUKDesignSystemFormBuilder
|
|
164
168
|
# = f.govuk_password_field :passcode,
|
165
169
|
# label: -> { tag.h3('What is your secret pass code?') }
|
166
170
|
#
|
167
|
-
def govuk_password_field(attribute_name, hint_text: nil, label: {}, width: nil, caption: {}, **args, &block)
|
168
|
-
Elements::Inputs::Password.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
171
|
+
def govuk_password_field(attribute_name, hint_text: nil, label: {}, width: nil, form_group_classes: nil, caption: {}, **args, &block)
|
172
|
+
Elements::Inputs::Password.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
169
173
|
end
|
170
174
|
|
171
175
|
# Generates a input of type +url+
|
@@ -183,6 +187,7 @@ module GOVUKDesignSystemFormBuilder
|
|
183
187
|
# @option caption text [String] the caption text
|
184
188
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
185
189
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
190
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
186
191
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
187
192
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
188
193
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -205,8 +210,8 @@ module GOVUKDesignSystemFormBuilder
|
|
205
210
|
# = f.govuk_url_field :work_website,
|
206
211
|
# label: -> { tag.h3("Enter your company's website") }
|
207
212
|
#
|
208
|
-
def govuk_url_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
209
|
-
Elements::Inputs::URL.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
213
|
+
def govuk_url_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
214
|
+
Elements::Inputs::URL.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
210
215
|
end
|
211
216
|
|
212
217
|
# Generates a input of type +number+
|
@@ -224,6 +229,7 @@ module GOVUKDesignSystemFormBuilder
|
|
224
229
|
# @option caption text [String] the caption text
|
225
230
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
226
231
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
232
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
227
233
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
228
234
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
229
235
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -249,8 +255,8 @@ module GOVUKDesignSystemFormBuilder
|
|
249
255
|
# = f.govuk_url_field :personal_best_over_100m,
|
250
256
|
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
|
251
257
|
#
|
252
|
-
def govuk_number_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, **args, &block)
|
253
|
-
Elements::Inputs::Number.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, **args, &block).html
|
258
|
+
def govuk_number_field(attribute_name, hint_text: nil, label: {}, caption: {}, width: nil, form_group_classes: nil, **args, &block)
|
259
|
+
Elements::Inputs::Number.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, width: width, form_group_classes: form_group_classes, **args, &block).html
|
254
260
|
end
|
255
261
|
|
256
262
|
# Generates a +textarea+ element with a label, optional hint. Also offers
|
@@ -272,6 +278,7 @@ module GOVUKDesignSystemFormBuilder
|
|
272
278
|
# @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
|
273
279
|
# @param rows [Integer] sets the initial number of rows
|
274
280
|
# @option args [Hash] args additional arguments are applied as attributes to the +textarea+ element
|
281
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
275
282
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
276
283
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
277
284
|
# @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
|
@@ -297,8 +304,8 @@ module GOVUKDesignSystemFormBuilder
|
|
297
304
|
# = f.govuk_text_area :instructions,
|
298
305
|
# label: -> { tag.h3("How do you set it up?") }
|
299
306
|
#
|
300
|
-
def govuk_text_area(attribute_name, hint_text: nil, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, **args, &block)
|
301
|
-
Elements::TextArea.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, **args, &block).html
|
307
|
+
def govuk_text_area(attribute_name, hint_text: nil, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group_classes: nil, **args, &block)
|
308
|
+
Elements::TextArea.new(self, object_name, attribute_name, hint_text: hint_text, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, form_group_classes: form_group_classes, **args, &block).html
|
302
309
|
end
|
303
310
|
|
304
311
|
# Generates a +select+ element containing +option+ for each member in the provided collection
|
@@ -312,7 +319,11 @@ module GOVUKDesignSystemFormBuilder
|
|
312
319
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
313
320
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
314
321
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
322
|
+
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
323
|
+
# @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
|
324
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
315
325
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
326
|
+
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
316
327
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
317
328
|
#
|
318
329
|
# @example A select box with hint
|
@@ -332,7 +343,7 @@ module GOVUKDesignSystemFormBuilder
|
|
332
343
|
# = f.govuk_collection_select(:team, @teams, :id, :name) do
|
333
344
|
# label: -> { tag.h3("Which team did you represent?") }
|
334
345
|
#
|
335
|
-
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint_text: nil, label: {}, caption: {}, &block)
|
346
|
+
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint_text: nil, label: {}, caption: {}, form_group_classes: nil, &block)
|
336
347
|
Elements::Select.new(
|
337
348
|
self,
|
338
349
|
object_name,
|
@@ -345,6 +356,7 @@ module GOVUKDesignSystemFormBuilder
|
|
345
356
|
caption: caption,
|
346
357
|
options: options,
|
347
358
|
html_options: html_options,
|
359
|
+
form_group_classes: form_group_classes,
|
348
360
|
&block
|
349
361
|
).html
|
350
362
|
end
|
@@ -373,7 +385,7 @@ module GOVUKDesignSystemFormBuilder
|
|
373
385
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
374
386
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
375
387
|
# @param bold_labels [Boolean] controls whether the radio button labels are bold
|
376
|
-
# @param classes [String] Classes to add to the radio button container.
|
388
|
+
# @param classes [Array,String] Classes to add to the radio button container.
|
377
389
|
# @option legend text [String] the fieldset legend's text content
|
378
390
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
379
391
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
@@ -415,7 +427,7 @@ module GOVUKDesignSystemFormBuilder
|
|
415
427
|
# :name,
|
416
428
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
417
429
|
#
|
418
|
-
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, &block)
|
430
|
+
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, form_group_classes: nil, &block)
|
419
431
|
Elements::Radios::Collection.new(
|
420
432
|
self,
|
421
433
|
object_name,
|
@@ -431,6 +443,7 @@ module GOVUKDesignSystemFormBuilder
|
|
431
443
|
small: small,
|
432
444
|
bold_labels: bold_labels,
|
433
445
|
classes: classes,
|
446
|
+
form_group_classes: form_group_classes,
|
434
447
|
&block
|
435
448
|
).html
|
436
449
|
end
|
@@ -454,8 +467,9 @@ module GOVUKDesignSystemFormBuilder
|
|
454
467
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
455
468
|
# @option caption text [String] the caption text
|
456
469
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
470
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
457
471
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
458
|
-
# @param classes [String] Classes to add to the radio button container.
|
472
|
+
# @param classes [Array,String] Classes to add to the radio button container.
|
459
473
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
460
474
|
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
461
475
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -477,8 +491,8 @@ module GOVUKDesignSystemFormBuilder
|
|
477
491
|
# = f.govuk_radio_button :burger_id, :regular, label: { text: 'Hamburger' }, link_errors: true
|
478
492
|
# = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
|
479
493
|
#
|
480
|
-
def govuk_radio_buttons_fieldset(attribute_name, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, classes: nil, &block)
|
481
|
-
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, inline: inline, small: small, classes: classes, &block).html
|
494
|
+
def govuk_radio_buttons_fieldset(attribute_name, hint_text: nil, legend: {}, caption: {}, inline: false, small: false, classes: nil, form_group_classes: nil, &block)
|
495
|
+
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, inline: inline, small: small, classes: classes, form_group_classes: form_group_classes, &block).html
|
482
496
|
end
|
483
497
|
|
484
498
|
# Generates a radio button
|
@@ -529,7 +543,7 @@ module GOVUKDesignSystemFormBuilder
|
|
529
543
|
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
530
544
|
# @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
|
531
545
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
532
|
-
# @param classes [String] Classes to add to the checkbox container.
|
546
|
+
# @param classes [Array,String] Classes to add to the checkbox container.
|
533
547
|
# @param legend [Hash,Proc] options for configuring the legend
|
534
548
|
# @option legend text [String] the fieldset legend's text content
|
535
549
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
@@ -538,6 +552,7 @@ module GOVUKDesignSystemFormBuilder
|
|
538
552
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
539
553
|
# @option caption text [String] the caption text
|
540
554
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
555
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
541
556
|
# @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
|
542
557
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
543
558
|
#
|
@@ -574,7 +589,7 @@ module GOVUKDesignSystemFormBuilder
|
|
574
589
|
# :name,
|
575
590
|
# legend: -> { tag.h3('What kind of sandwich do you want?') }
|
576
591
|
#
|
577
|
-
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, small: false, classes: nil, &block)
|
592
|
+
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint_text: nil, legend: {}, caption: {}, small: false, classes: nil, form_group_classes: nil, &block)
|
578
593
|
Elements::CheckBoxes::Collection.new(
|
579
594
|
self,
|
580
595
|
object_name,
|
@@ -588,6 +603,7 @@ module GOVUKDesignSystemFormBuilder
|
|
588
603
|
caption: caption,
|
589
604
|
small: small,
|
590
605
|
classes: classes,
|
606
|
+
form_group_classes: form_group_classes,
|
591
607
|
&block
|
592
608
|
).html
|
593
609
|
end
|
@@ -608,7 +624,8 @@ module GOVUKDesignSystemFormBuilder
|
|
608
624
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
609
625
|
# @option caption text [String] the caption text
|
610
626
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
611
|
-
# @param classes [String] Classes to add to the checkbox container.
|
627
|
+
# @param classes [Array,String] Classes to add to the checkbox container.
|
628
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
612
629
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
613
630
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
614
631
|
#
|
@@ -622,7 +639,7 @@ module GOVUKDesignSystemFormBuilder
|
|
622
639
|
# = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
|
623
640
|
# = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
|
624
641
|
#
|
625
|
-
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint_text: {}, small: false, classes: nil, &block)
|
642
|
+
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint_text: {}, small: false, classes: nil, form_group_classes: nil, &block)
|
626
643
|
Containers::CheckBoxesFieldset.new(
|
627
644
|
self,
|
628
645
|
object_name,
|
@@ -632,6 +649,7 @@ module GOVUKDesignSystemFormBuilder
|
|
632
649
|
caption: caption,
|
633
650
|
small: small,
|
634
651
|
classes: classes,
|
652
|
+
form_group_classes: form_group_classes,
|
635
653
|
&block
|
636
654
|
).html
|
637
655
|
end
|
@@ -677,7 +695,7 @@ module GOVUKDesignSystemFormBuilder
|
|
677
695
|
# @param text [String] the button text
|
678
696
|
# @param warning [Boolean] makes the button red ({https://design-system.service.gov.uk/components/button/#warning-buttons warning}) when true
|
679
697
|
# @param secondary [Boolean] makes the button grey ({https://design-system.service.gov.uk/components/button/#secondary-buttons secondary}) when true
|
680
|
-
# @param classes [String] Classes to add to the submit button
|
698
|
+
# @param classes [Array,String] Classes to add to the submit button
|
681
699
|
# @param prevent_double_click [Boolean] adds JavaScript to safeguard the
|
682
700
|
# form from being submitted more than once
|
683
701
|
# @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
|
@@ -718,6 +736,7 @@ module GOVUKDesignSystemFormBuilder
|
|
718
736
|
# @option caption text [String] the caption text
|
719
737
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
720
738
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
739
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
721
740
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
722
741
|
# @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
|
723
742
|
# will be added to the inputs
|
@@ -737,8 +756,8 @@ module GOVUKDesignSystemFormBuilder
|
|
737
756
|
# @example A date input with legend supplied as a proc
|
738
757
|
# = f.govuk_date_field :finishes_on,
|
739
758
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
740
|
-
def govuk_date_field(attribute_name, hint_text: nil, legend: {}, caption: {}, date_of_birth: false, omit_day: false, &block)
|
741
|
-
Elements::Date.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, &block).html
|
759
|
+
def govuk_date_field(attribute_name, hint_text: nil, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group_classes: nil, &block)
|
760
|
+
Elements::Date.new(self, object_name, attribute_name, hint_text: hint_text, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group_classes: form_group_classes, &block).html
|
742
761
|
end
|
743
762
|
|
744
763
|
# Generates a summary of errors in the form, each linking to the corresponding
|
@@ -796,6 +815,7 @@ module GOVUKDesignSystemFormBuilder
|
|
796
815
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
797
816
|
# @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
|
798
817
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
818
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
799
819
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
800
820
|
#
|
801
821
|
# @example A photo upload field with file type specifier and injected content
|
@@ -814,8 +834,8 @@ module GOVUKDesignSystemFormBuilder
|
|
814
834
|
# @note Remember to set +multipart: true+ when creating a form with file
|
815
835
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
816
836
|
# the Rails documentation} for more information
|
817
|
-
def govuk_file_field(attribute_name, label: {}, caption: {}, hint_text: nil, **args, &block)
|
818
|
-
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint_text: hint_text, **args, &block).html
|
837
|
+
def govuk_file_field(attribute_name, label: {}, caption: {}, hint_text: nil, form_group_classes: nil, **args, &block)
|
838
|
+
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint_text: hint_text, form_group_classes: form_group_classes, **args, &block).html
|
819
839
|
end
|
820
840
|
end
|
821
841
|
end
|
@@ -14,17 +14,18 @@ module GOVUKDesignSystemFormBuilder
|
|
14
14
|
def html
|
15
15
|
return yield unless limit?
|
16
16
|
|
17
|
-
content_tag(
|
18
|
-
'div',
|
19
|
-
class: %(#{brand}-character-count),
|
20
|
-
data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
|
21
|
-
) do
|
22
|
-
yield
|
23
|
-
end
|
17
|
+
content_tag('div', **options) { yield }
|
24
18
|
end
|
25
19
|
|
26
20
|
private
|
27
21
|
|
22
|
+
def options
|
23
|
+
{
|
24
|
+
class: %(#{brand}-character-count),
|
25
|
+
data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
28
29
|
def limit
|
29
30
|
if @max_words
|
30
31
|
{ maxwords: @max_words }
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Containers
|
3
3
|
class CheckBoxes < Base
|
4
|
-
using PrefixableArray
|
5
|
-
|
6
4
|
def initialize(builder, small:, classes: nil)
|
7
5
|
@builder = builder
|
8
6
|
@small = small
|
@@ -10,18 +8,28 @@ module GOVUKDesignSystemFormBuilder
|
|
10
8
|
end
|
11
9
|
|
12
10
|
def html
|
13
|
-
content_tag('div',
|
14
|
-
yield
|
15
|
-
end
|
11
|
+
content_tag('div', **options) { yield }
|
16
12
|
end
|
17
13
|
|
18
14
|
private
|
19
15
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
def options
|
17
|
+
{
|
18
|
+
class: classes,
|
19
|
+
data: { module: %(#{brand}-checkboxes) }
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def classes
|
24
|
+
[%(#{brand}-checkboxes), small_class, custom_classes].flatten.compact
|
25
|
+
end
|
26
|
+
|
27
|
+
def small_class
|
28
|
+
%(#{brand}-checkboxes--small) if @small
|
29
|
+
end
|
30
|
+
|
31
|
+
def custom_classes
|
32
|
+
Array.wrap(@classes)
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
@@ -4,20 +4,21 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
include Traits::Error
|
5
5
|
include Traits::Hint
|
6
6
|
|
7
|
-
def initialize(builder, object_name, attribute_name, hint_text:, legend:, caption:, small:, classes:, &block)
|
7
|
+
def initialize(builder, object_name, attribute_name, hint_text:, legend:, caption:, small:, classes:, form_group_classes:, &block)
|
8
8
|
super(builder, object_name, attribute_name, &block)
|
9
9
|
|
10
|
-
@legend
|
11
|
-
@caption
|
12
|
-
@hint_text
|
13
|
-
@small
|
14
|
-
@classes
|
15
|
-
@
|
10
|
+
@legend = legend
|
11
|
+
@caption = caption
|
12
|
+
@hint_text = hint_text
|
13
|
+
@small = small
|
14
|
+
@classes = classes
|
15
|
+
@form_group_classes = form_group_classes
|
16
|
+
@block_content = capture { block.call }
|
16
17
|
end
|
17
18
|
|
18
19
|
def html
|
19
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
20
|
-
Containers::Fieldset.new(@builder, @object_name, @attribute_name,
|
20
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, classes: @form_group_classes).html do
|
21
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
21
22
|
safe_join([hint_element, error_element, checkboxes])
|
22
23
|
end
|
23
24
|
end
|
@@ -25,6 +26,14 @@ module GOVUKDesignSystemFormBuilder
|
|
25
26
|
|
26
27
|
private
|
27
28
|
|
29
|
+
def fieldset_options
|
30
|
+
{
|
31
|
+
legend: @legend,
|
32
|
+
caption: @caption,
|
33
|
+
described_by: [error_element.error_id, hint_element.hint_id]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
28
37
|
def checkboxes
|
29
38
|
Containers::CheckBoxes.new(@builder, small: @small, classes: @classes).html do
|
30
39
|
@block_content
|