govuk_design_system_formbuilder 1.2.0 → 1.2.5
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.rb +4 -0
- data/lib/govuk_design_system_formbuilder/base.rb +5 -0
- data/lib/govuk_design_system_formbuilder/builder.rb +52 -33
- 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 +27 -18
- 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 +28 -19
- 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 +29 -23
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +17 -15
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +28 -32
- data/lib/govuk_design_system_formbuilder/elements/date.rb +55 -51
- data/lib/govuk_design_system_formbuilder/elements/error_message.rb +7 -6
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +24 -27
- data/lib/govuk_design_system_formbuilder/elements/file.rb +21 -22
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +13 -16
- data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/label.rb +40 -29
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +79 -0
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +46 -36
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +24 -14
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +18 -19
- data/lib/govuk_design_system_formbuilder/elements/select.rb +28 -34
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +34 -25
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +39 -40
- data/lib/govuk_design_system_formbuilder/traits/caption.rb +5 -6
- data/lib/govuk_design_system_formbuilder/traits/input.rb +21 -29
- data/lib/govuk_design_system_formbuilder/traits/label.rb +2 -2
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +16 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 702ad71c46989cfeb455ced19e6c9c426685947bac6c6057f902bf1deb44eb97
|
4
|
+
data.tar.gz: 263eda546cf3f17b3611613e77c0f24f9c52995015752c4cc534f914b0c689be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063007b8ff7a1ab6c2bb1c470b36895047217d8149b84fb1a9b8aac12b0a3d5e7910828bd0e44bc2aafafa972f4c5f032bea0bc55cd7ae60fe99c32a716a9156
|
7
|
+
data.tar.gz: 20cd7ac352b111277d57843b810eebb6cb73ef50c719501115b8a6f91264abd4b34646431c6ae9794df88378c0ee4f0bc835c7a5c633b3b251003581b0353664
|
@@ -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',
|
@@ -18,6 +18,11 @@ module GOVUKDesignSystemFormBuilder
|
|
18
18
|
@block_content = capture { block.call } if block_given?
|
19
19
|
end
|
20
20
|
|
21
|
+
# objects that implement #to_s can be passed directly into #safe_join
|
22
|
+
def to_s
|
23
|
+
html || ''
|
24
|
+
end
|
25
|
+
|
21
26
|
private
|
22
27
|
|
23
28
|
def brand(override = nil)
|
@@ -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,14 +695,13 @@ 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
|
-
# @
|
681
|
-
# should probably be supported too
|
682
|
-
# @param classes [String] Classes to add to the submit button
|
698
|
+
# @param classes [Array,String] Classes to add to the submit button
|
683
699
|
# @param prevent_double_click [Boolean] adds JavaScript to safeguard the
|
684
700
|
# form from being submitted more than once
|
685
701
|
# @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
|
686
702
|
# client-side validation provided by the browser. This is to provide a more consistent and accessible user
|
687
703
|
# experience
|
704
|
+
# @param disabled [Boolean] makes the button disabled when true
|
688
705
|
# @param block [Block] Any supplied HTML will be inserted immediately after
|
689
706
|
# the submit button. It is intended for other buttons directly related to
|
690
707
|
# the form's operation, such as 'Cancel' or 'Safe draft'
|
@@ -699,8 +716,8 @@ module GOVUKDesignSystemFormBuilder
|
|
699
716
|
# = f.govuk_submit "Proceed", prevent_double_click: true do
|
700
717
|
# = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
|
701
718
|
#
|
702
|
-
def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, classes: nil, prevent_double_click: true, validate: false, &block)
|
703
|
-
Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, &block).html
|
719
|
+
def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, classes: nil, prevent_double_click: true, validate: false, disabled: false, &block)
|
720
|
+
Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, &block).html
|
704
721
|
end
|
705
722
|
|
706
723
|
# Generates three inputs for the +day+, +month+ and +year+ components of a date
|
@@ -719,6 +736,7 @@ module GOVUKDesignSystemFormBuilder
|
|
719
736
|
# @option caption text [String] the caption text
|
720
737
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
721
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+
|
722
740
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
723
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}
|
724
742
|
# will be added to the inputs
|
@@ -738,8 +756,8 @@ module GOVUKDesignSystemFormBuilder
|
|
738
756
|
# @example A date input with legend supplied as a proc
|
739
757
|
# = f.govuk_date_field :finishes_on,
|
740
758
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
741
|
-
def govuk_date_field(attribute_name, hint_text: nil, legend: {}, caption: {}, date_of_birth: false, omit_day: false, &block)
|
742
|
-
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
|
743
761
|
end
|
744
762
|
|
745
763
|
# Generates a summary of errors in the form, each linking to the corresponding
|
@@ -797,6 +815,7 @@ module GOVUKDesignSystemFormBuilder
|
|
797
815
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
798
816
|
# @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
|
799
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+
|
800
819
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
801
820
|
#
|
802
821
|
# @example A photo upload field with file type specifier and injected content
|
@@ -815,8 +834,8 @@ module GOVUKDesignSystemFormBuilder
|
|
815
834
|
# @note Remember to set +multipart: true+ when creating a form with file
|
816
835
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
817
836
|
# the Rails documentation} for more information
|
818
|
-
def govuk_file_field(attribute_name, label: {}, caption: {}, hint_text: nil, **args, &block)
|
819
|
-
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
|
820
839
|
end
|
821
840
|
end
|
822
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,32 +4,41 @@ 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,
|
21
|
-
safe_join(
|
22
|
-
[
|
23
|
-
hint_element.html,
|
24
|
-
error_element.html,
|
25
|
-
Containers::CheckBoxes.new(@builder, small: @small, classes: @classes).html do
|
26
|
-
@block_content
|
27
|
-
end
|
28
|
-
]
|
29
|
-
)
|
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
|
22
|
+
safe_join([hint_element, error_element, checkboxes])
|
30
23
|
end
|
31
24
|
end
|
32
25
|
end
|
26
|
+
|
27
|
+
private
|
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
|
+
|
37
|
+
def checkboxes
|
38
|
+
Containers::CheckBoxes.new(@builder, small: @small, classes: @classes).html do
|
39
|
+
@block_content
|
40
|
+
end
|
41
|
+
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
end
|