govuk_design_system_formbuilder 1.2.3 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/govuk_design_system_formbuilder.rb +1 -1
- data/lib/govuk_design_system_formbuilder/base.rb +1 -1
- data/lib/govuk_design_system_formbuilder/builder.rb +53 -31
- 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 +6 -4
- 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 +3 -5
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +24 -19
- data/lib/govuk_design_system_formbuilder/elements/date.rb +51 -44
- data/lib/govuk_design_system_formbuilder/elements/error_message.rb +4 -4
- 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 -2
- data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +0 -2
- data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +0 -2
- data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +0 -2
- data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +0 -2
- data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +0 -2
- data/lib/govuk_design_system_formbuilder/elements/label.rb +30 -26
- 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 +15 -7
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +8 -4
- data/lib/govuk_design_system_formbuilder/elements/select.rb +24 -19
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +11 -6
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +31 -25
- data/lib/govuk_design_system_formbuilder/traits/collection_item.rb +1 -1
- data/lib/govuk_design_system_formbuilder/traits/conditional.rb +1 -1
- 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 +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c6269db9ed06ab08bc6bfa1d561b88da157c4b473e4560d0de0dd8038e7f87e
|
4
|
+
data.tar.gz: ded604de8c561002ae266f1b2a6ba36398947eea3dc868be2330345cd39fc6ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e7844dd37618342514e85bdaab2756fa2ea842545eb26e0ca42a17f95095080a78192fea747bfc829283b446f0fee16ef5f2e7a6c854615e3af90df63f982fa
|
7
|
+
data.tar.gz: ab5f73b61f765ccf659f48e939593e5738d85127fd1854a59f60d749af4e0ead6255e5f15df4b4e1f930d07b4279bbfeca80c8b53302d332570fda642ad72a20
|
data/README.md
CHANGED
@@ -7,10 +7,10 @@
|
|
7
7
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/fde73b5dc9476197281b/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/test_coverage)
|
8
8
|
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=DFE-Digital/govuk_design_system_formbuilder)](https://dependabot.com)
|
9
9
|
[![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk_design_system_formbuilder)](https://github.com/DFE-Digital/govuk_design_system_formbuilder/blob/master/LICENSE)
|
10
|
-
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.
|
10
|
+
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.8.1-brightgreen)](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.1 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
|
@@ -88,7 +88,7 @@ module GOVUKDesignSystemFormBuilder
|
|
88
88
|
end
|
89
89
|
|
90
90
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
91
|
-
delegate :content_tag, :tag, :safe_join, :
|
91
|
+
delegate :content_tag, :tag, :safe_join, :link_to, :capture, to: :@template
|
92
92
|
|
93
93
|
include GOVUKDesignSystemFormBuilder::Builder
|
94
94
|
end
|
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class Base
|
11
|
-
delegate :
|
11
|
+
delegate :content_tag, :safe_join, :tag, :link_to, :capture, to: :@builder
|
12
12
|
delegate :config, to: GOVUKDesignSystemFormBuilder
|
13
13
|
|
14
14
|
def initialize(builder, object_name, attribute_name, &block)
|
@@ -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
|
@@ -640,6 +658,7 @@ module GOVUKDesignSystemFormBuilder
|
|
640
658
|
#
|
641
659
|
# @param attribute_name [Symbol] The name of the attribute
|
642
660
|
# @param value [Boolean,String,Symbol,Integer] The value of the checkbox when it is checked
|
661
|
+
# @param unchecked_value [Boolean,String,Symbol,Integer] The value of the checkbox when it is unchecked
|
643
662
|
# @param hint_text [String] the contents of the hint
|
644
663
|
# @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
|
645
664
|
# @option label text [String] the label text
|
@@ -658,12 +677,13 @@ module GOVUKDesignSystemFormBuilder
|
|
658
677
|
# label: { text: 'Do you agree with our terms and conditions?' },
|
659
678
|
# hint_text: 'You will not be able to proceed unless you do'
|
660
679
|
#
|
661
|
-
def govuk_check_box(attribute_name,
|
680
|
+
def govuk_check_box(attribute_name, checked_value, unchecked_value = false, hint_text: nil, label: {}, link_errors: false, multiple: true, &block)
|
662
681
|
Elements::CheckBoxes::FieldsetCheckBox.new(
|
663
682
|
self,
|
664
683
|
object_name,
|
665
684
|
attribute_name,
|
666
|
-
|
685
|
+
checked_value,
|
686
|
+
unchecked_value,
|
667
687
|
hint_text: hint_text,
|
668
688
|
label: label,
|
669
689
|
link_errors: link_errors,
|
@@ -677,7 +697,7 @@ module GOVUKDesignSystemFormBuilder
|
|
677
697
|
# @param text [String] the button text
|
678
698
|
# @param warning [Boolean] makes the button red ({https://design-system.service.gov.uk/components/button/#warning-buttons warning}) when true
|
679
699
|
# @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
|
700
|
+
# @param classes [Array,String] Classes to add to the submit button
|
681
701
|
# @param prevent_double_click [Boolean] adds JavaScript to safeguard the
|
682
702
|
# form from being submitted more than once
|
683
703
|
# @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
|
@@ -718,6 +738,7 @@ module GOVUKDesignSystemFormBuilder
|
|
718
738
|
# @option caption text [String] the caption text
|
719
739
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
720
740
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
741
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
721
742
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
722
743
|
# @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
744
|
# will be added to the inputs
|
@@ -737,8 +758,8 @@ module GOVUKDesignSystemFormBuilder
|
|
737
758
|
# @example A date input with legend supplied as a proc
|
738
759
|
# = f.govuk_date_field :finishes_on,
|
739
760
|
# 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
|
761
|
+
def govuk_date_field(attribute_name, hint_text: nil, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group_classes: nil, &block)
|
762
|
+
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
763
|
end
|
743
764
|
|
744
765
|
# Generates a summary of errors in the form, each linking to the corresponding
|
@@ -796,6 +817,7 @@ module GOVUKDesignSystemFormBuilder
|
|
796
817
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
797
818
|
# @param hint_text [String] The content of the hint. No hint will be injected if left +nil+
|
798
819
|
# @option args [Hash] args additional arguments are applied as attributes to the +input+ element
|
820
|
+
# @param form_group_classes [Array,String] Classes to add to the surrounding +form-group+
|
799
821
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
800
822
|
#
|
801
823
|
# @example A photo upload field with file type specifier and injected content
|
@@ -814,8 +836,8 @@ module GOVUKDesignSystemFormBuilder
|
|
814
836
|
# @note Remember to set +multipart: true+ when creating a form with file
|
815
837
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
816
838
|
# 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
|
839
|
+
def govuk_file_field(attribute_name, label: {}, caption: {}, hint_text: nil, form_group_classes: nil, **args, &block)
|
840
|
+
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
841
|
end
|
820
842
|
end
|
821
843
|
end
|
@@ -14,17 +14,18 @@ module GOVUKDesignSystemFormBuilder
|
|
14
14
|
def html
|
15
15
|
return yield unless limit?
|
16
16
|
|
17
|
-
|
18
|
-
'div',
|
19
|
-
class: %(#{brand}-character-count),
|
20
|
-
data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
|
21
|
-
) do
|
22
|
-
yield
|
23
|
-
end
|
17
|
+
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
|
-
|
14
|
-
yield
|
15
|
-
end
|
11
|
+
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
|