govuk_design_system_formbuilder 1.2.4 → 2.0.0b2
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 +1 -1
- data/lib/govuk_design_system_formbuilder/base.rb +1 -1
- data/lib/govuk_design_system_formbuilder/builder.rb +201 -78
- data/lib/govuk_design_system_formbuilder/containers/character_count.rb +2 -2
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +13 -12
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +4 -3
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +12 -62
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +19 -10
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +4 -3
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +17 -13
- data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +3 -1
- data/lib/govuk_design_system_formbuilder/elements/caption.rb +14 -7
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +12 -11
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +9 -7
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +19 -15
- data/lib/govuk_design_system_formbuilder/elements/date.rb +18 -17
- 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 +37 -10
- 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 +28 -22
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +87 -0
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +14 -13
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +13 -7
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +15 -7
- data/lib/govuk_design_system_formbuilder/elements/select.rb +18 -17
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +9 -4
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +10 -9
- data/lib/govuk_design_system_formbuilder/traits/caption.rb +1 -9
- 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/hint.rb +15 -2
- data/lib/govuk_design_system_formbuilder/traits/input.rb +4 -3
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd1f1c56336a4852ae5915c148e7c47abeef5590f87fc083437a4f4a680addba
|
4
|
+
data.tar.gz: 929a16808249de59a675c3215837e1522d2982a46497fea6b207e90f9c9d8aa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad2ad55fb5f7752862fde79ec8ffcfba5ef9cb1ea20e30b266c7152a7d78eef6fa9f40682f69a7db395b9f8104645735eb71c1efbc538506d3015fb888542932
|
7
|
+
data.tar.gz: 2c1d49579c09742a5dc2f8be8ddf7bcee4edb6d2d9d39e610705dfd10efc4bf0df18ad00026cd932d10b790aca1ee93a964079329ee9be0067c4c4f84c84a83a
|
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.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)
|
@@ -5,7 +5,11 @@ module GOVUKDesignSystemFormBuilder
|
|
5
5
|
# Generates a input of type +text+
|
6
6
|
#
|
7
7
|
# @param attribute_name [Symbol] The name of the attribute
|
8
|
-
# @param
|
8
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
9
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
10
|
+
# @option hint text [String] the hint text
|
11
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
12
|
+
#
|
9
13
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
10
14
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
11
15
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -13,10 +17,15 @@ module GOVUKDesignSystemFormBuilder
|
|
13
17
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
14
18
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
15
19
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
20
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
16
21
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
17
22
|
# @option caption text [String] the caption text
|
18
23
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
19
|
-
# @option
|
24
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
25
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
26
|
+
# @param form_group [Hash] configures the form group
|
27
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
28
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
20
29
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
21
30
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
22
31
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -25,7 +34,7 @@ module GOVUKDesignSystemFormBuilder
|
|
25
34
|
# @example A required full name field with a placeholder
|
26
35
|
# = f.govuk_text_field :name,
|
27
36
|
# label: { text: 'Full name' },
|
28
|
-
#
|
37
|
+
# hint: { text: 'It says it on your birth certificate' },
|
29
38
|
# required: true,
|
30
39
|
# placeholder: 'Ralph Wiggum'
|
31
40
|
#
|
@@ -40,14 +49,17 @@ module GOVUKDesignSystemFormBuilder
|
|
40
49
|
# = f.govuk_text_field :callsign,
|
41
50
|
# label: -> { tag.h3('Call-sign') }
|
42
51
|
#
|
43
|
-
def govuk_text_field(attribute_name,
|
44
|
-
Elements::Inputs::Text.new(self, object_name, attribute_name,
|
52
|
+
def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
53
|
+
Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
45
54
|
end
|
46
55
|
|
47
56
|
# Generates a input of type +tel+
|
48
57
|
#
|
49
58
|
# @param attribute_name [Symbol] The name of the attribute
|
50
|
-
# @param
|
59
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
60
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
61
|
+
# @option hint text [String] the hint text
|
62
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
51
63
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
52
64
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
53
65
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -55,10 +67,15 @@ module GOVUKDesignSystemFormBuilder
|
|
55
67
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
56
68
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
57
69
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
70
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
58
71
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
59
72
|
# @option caption text [String] the caption text
|
60
73
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
61
|
-
# @option
|
74
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
75
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
76
|
+
# @param form_group [Hash] configures the form group
|
77
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
78
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
62
79
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
63
80
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
64
81
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -68,7 +85,7 @@ module GOVUKDesignSystemFormBuilder
|
|
68
85
|
# @example A required phone number field with a placeholder
|
69
86
|
# = f.govuk_phone_field :phone_number,
|
70
87
|
# label: { text: 'UK telephone number' },
|
71
|
-
#
|
88
|
+
# hint: { text: 'Include the dialling code' },
|
72
89
|
# required: true,
|
73
90
|
# placeholder: '0123 456 789'
|
74
91
|
#
|
@@ -83,14 +100,17 @@ module GOVUKDesignSystemFormBuilder
|
|
83
100
|
# = f.govuk_phone_field :work_number,
|
84
101
|
# label: -> { tag.h3('Work number') }
|
85
102
|
#
|
86
|
-
def govuk_phone_field(attribute_name,
|
87
|
-
Elements::Inputs::Phone.new(self, object_name, attribute_name,
|
103
|
+
def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
104
|
+
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
88
105
|
end
|
89
106
|
|
90
107
|
# Generates a input of type +email+
|
91
108
|
#
|
92
109
|
# @param attribute_name [Symbol] The name of the attribute
|
93
|
-
# @param
|
110
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
111
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
112
|
+
# @option hint text [String] the hint text
|
113
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
94
114
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
95
115
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
96
116
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -98,10 +118,15 @@ module GOVUKDesignSystemFormBuilder
|
|
98
118
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
99
119
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
100
120
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
121
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
101
122
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
102
123
|
# @option caption text [String] the caption text
|
103
124
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
104
|
-
# @option
|
125
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
126
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
127
|
+
# @param form_group [Hash] configures the form group
|
128
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
129
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
105
130
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
106
131
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
107
132
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -124,14 +149,17 @@ module GOVUKDesignSystemFormBuilder
|
|
124
149
|
# = f.govuk_email_field :personal_email,
|
125
150
|
# label: -> { tag.h3('Personal email address') }
|
126
151
|
#
|
127
|
-
def govuk_email_field(attribute_name,
|
128
|
-
Elements::Inputs::Email.new(self, object_name, attribute_name,
|
152
|
+
def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
153
|
+
Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
129
154
|
end
|
130
155
|
|
131
156
|
# Generates a input of type +password+
|
132
157
|
#
|
133
158
|
# @param attribute_name [Symbol] The name of the attribute
|
134
|
-
# @param
|
159
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
160
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
161
|
+
# @option hint text [String] the hint text
|
162
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
135
163
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
136
164
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
137
165
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -139,10 +167,15 @@ module GOVUKDesignSystemFormBuilder
|
|
139
167
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
140
168
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
141
169
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
170
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
142
171
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
143
172
|
# @option caption text [String] the caption text
|
144
173
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
145
|
-
# @option
|
174
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
175
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
176
|
+
# @param form_group [Hash] configures the form group
|
177
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
178
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
146
179
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
147
180
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
148
181
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -164,14 +197,17 @@ module GOVUKDesignSystemFormBuilder
|
|
164
197
|
# = f.govuk_password_field :passcode,
|
165
198
|
# label: -> { tag.h3('What is your secret pass code?') }
|
166
199
|
#
|
167
|
-
def govuk_password_field(attribute_name,
|
168
|
-
Elements::Inputs::Password.new(self, object_name, attribute_name,
|
200
|
+
def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, form_group: {}, caption: {}, **kwargs, &block)
|
201
|
+
Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
169
202
|
end
|
170
203
|
|
171
204
|
# Generates a input of type +url+
|
172
205
|
#
|
173
206
|
# @param attribute_name [Symbol] The name of the attribute
|
174
|
-
# @param
|
207
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
208
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
209
|
+
# @option hint text [String] the hint text
|
210
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
175
211
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
176
212
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
177
213
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -179,10 +215,15 @@ module GOVUKDesignSystemFormBuilder
|
|
179
215
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
180
216
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
181
217
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
218
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
182
219
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
183
220
|
# @option caption text [String] the caption text
|
184
221
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
185
|
-
# @option
|
222
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
223
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
224
|
+
# @param form_group [Hash] configures the form group
|
225
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
226
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
186
227
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
187
228
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
188
229
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -205,14 +246,17 @@ module GOVUKDesignSystemFormBuilder
|
|
205
246
|
# = f.govuk_url_field :work_website,
|
206
247
|
# label: -> { tag.h3("Enter your company's website") }
|
207
248
|
#
|
208
|
-
def govuk_url_field(attribute_name,
|
209
|
-
Elements::Inputs::URL.new(self, object_name, attribute_name,
|
249
|
+
def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
250
|
+
Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
210
251
|
end
|
211
252
|
|
212
253
|
# Generates a input of type +number+
|
213
254
|
#
|
214
255
|
# @param attribute_name [Symbol] The name of the attribute
|
215
|
-
# @param
|
256
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
257
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
258
|
+
# @option hint text [String] the hint text
|
259
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
216
260
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
217
261
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
218
262
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -220,10 +264,15 @@ module GOVUKDesignSystemFormBuilder
|
|
220
264
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
221
265
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
222
266
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
267
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
223
268
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
224
269
|
# @option caption text [String] the caption text
|
225
270
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
226
|
-
# @option
|
271
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
272
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
273
|
+
# @param form_group [Hash] configures the form group
|
274
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
275
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
227
276
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
228
277
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
229
278
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -249,8 +298,8 @@ module GOVUKDesignSystemFormBuilder
|
|
249
298
|
# = f.govuk_url_field :personal_best_over_100m,
|
250
299
|
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
|
251
300
|
#
|
252
|
-
def govuk_number_field(attribute_name,
|
253
|
-
Elements::Inputs::Number.new(self, object_name, attribute_name,
|
301
|
+
def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
302
|
+
Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
254
303
|
end
|
255
304
|
|
256
305
|
# Generates a +textarea+ element with a label, optional hint. Also offers
|
@@ -258,20 +307,28 @@ module GOVUKDesignSystemFormBuilder
|
|
258
307
|
# automatically
|
259
308
|
#
|
260
309
|
# @param attribute_name [Symbol] The name of the attribute
|
261
|
-
# @param
|
310
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
311
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
312
|
+
# @option hint text [String] the hint text
|
313
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
262
314
|
# @param label [Hash,Proc] configures or sets the associated label content
|
263
315
|
# @option label text [String] the label text
|
264
316
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
265
317
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
266
318
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
319
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
267
320
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
268
321
|
# @option caption text [String] the caption text
|
269
322
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
323
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
270
324
|
# @param max_words [Integer] adds the GOV.UK max word count
|
271
325
|
# @param max_chars [Integer] adds the GOV.UK max characters count
|
272
326
|
# @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
|
273
327
|
# @param rows [Integer] sets the initial number of rows
|
274
|
-
# @option
|
328
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +textarea+ element
|
329
|
+
# @param form_group [Hash] configures the form group
|
330
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
331
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
275
332
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
276
333
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
277
334
|
# @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
|
@@ -297,8 +354,8 @@ module GOVUKDesignSystemFormBuilder
|
|
297
354
|
# = f.govuk_text_area :instructions,
|
298
355
|
# label: -> { tag.h3("How do you set it up?") }
|
299
356
|
#
|
300
|
-
def govuk_text_area(attribute_name,
|
301
|
-
Elements::TextArea.new(self, object_name, attribute_name,
|
357
|
+
def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block)
|
358
|
+
Elements::TextArea.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, max_words: max_words, max_chars: max_chars, rows: rows, threshold: threshold, form_group: form_group, **kwargs, &block).html
|
302
359
|
end
|
303
360
|
|
304
361
|
# Generates a +select+ element containing +option+ for each member in the provided collection
|
@@ -307,13 +364,20 @@ module GOVUKDesignSystemFormBuilder
|
|
307
364
|
# @param collection [Enumerable<Object>] Options to be added to the +select+ element
|
308
365
|
# @param value_method [Symbol] The method called against each member of the collection to provide the value
|
309
366
|
# @param text_method [Symbol] The method called against each member of the collection to provide the text
|
310
|
-
# @param
|
367
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
368
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
369
|
+
# @option hint text [String] the hint text
|
370
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
311
371
|
# @option label text [String] the label text
|
312
372
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
313
373
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
314
374
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
375
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
315
376
|
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
316
377
|
# @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
|
378
|
+
# @param form_group [Hash] configures the form group
|
379
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
380
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
317
381
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
318
382
|
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
319
383
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -323,7 +387,7 @@ module GOVUKDesignSystemFormBuilder
|
|
323
387
|
# @grades,
|
324
388
|
# :id,
|
325
389
|
# :name,
|
326
|
-
#
|
390
|
+
# hint: { text: "If you took the test more than once enter your highest grade" }
|
327
391
|
#
|
328
392
|
# @example A select box with injected content
|
329
393
|
# = f.govuk_collection_select(:favourite_colour, @colours, :id, :name) do
|
@@ -335,7 +399,7 @@ module GOVUKDesignSystemFormBuilder
|
|
335
399
|
# = f.govuk_collection_select(:team, @teams, :id, :name) do
|
336
400
|
# label: -> { tag.h3("Which team did you represent?") }
|
337
401
|
#
|
338
|
-
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {},
|
402
|
+
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint: {}, label: {}, caption: {}, form_group: {}, &block)
|
339
403
|
Elements::Select.new(
|
340
404
|
self,
|
341
405
|
object_name,
|
@@ -343,11 +407,12 @@ module GOVUKDesignSystemFormBuilder
|
|
343
407
|
collection,
|
344
408
|
value_method: value_method,
|
345
409
|
text_method: text_method,
|
346
|
-
|
410
|
+
hint: hint,
|
347
411
|
label: label,
|
348
412
|
caption: caption,
|
349
413
|
options: options,
|
350
414
|
html_options: html_options,
|
415
|
+
form_group: form_group,
|
351
416
|
&block
|
352
417
|
).html
|
353
418
|
end
|
@@ -371,19 +436,24 @@ module GOVUKDesignSystemFormBuilder
|
|
371
436
|
# @param hint_method [Symbol, Proc, nil] The method called against each member of the collection to provide the hint text.
|
372
437
|
# When a +Proc+ is provided it must take a single argument that is a single member of the collection.
|
373
438
|
# When a +nil+ value is provided the hint text will be retrieved from the locale. This is the default and param can be omitted.
|
374
|
-
# @param
|
375
|
-
#
|
439
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
440
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
441
|
+
# @option hint text [String] the hint text
|
442
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
443
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
376
444
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
377
445
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
378
446
|
# @param bold_labels [Boolean] controls whether the radio button labels are bold
|
379
|
-
# @param classes [String] Classes to add to the radio button container.
|
447
|
+
# @param classes [Array,String] Classes to add to the radio button container.
|
380
448
|
# @option legend text [String] the fieldset legend's text content
|
381
449
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
382
450
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
383
451
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
452
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
384
453
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
385
454
|
# @option caption text [String] the caption text
|
386
455
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
456
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
387
457
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
388
458
|
#
|
389
459
|
# @example A collection of radio buttons for favourite colours, labels capitalised via a proc
|
@@ -399,7 +469,7 @@ module GOVUKDesignSystemFormBuilder
|
|
399
469
|
# ->(option) { option.name.upcase },
|
400
470
|
# :description,
|
401
471
|
# legend: { text: 'Pick your favourite colour', size: 'm' },
|
402
|
-
#
|
472
|
+
# hint: { text: 'If you cannot find the exact match choose something close' },
|
403
473
|
# inline: false
|
404
474
|
#
|
405
475
|
# @example A collection of radio buttons for grades with injected content
|
@@ -418,7 +488,7 @@ module GOVUKDesignSystemFormBuilder
|
|
418
488
|
# :name,
|
419
489
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
420
490
|
#
|
421
|
-
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil,
|
491
|
+
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, form_group: {}, &block)
|
422
492
|
Elements::Radios::Collection.new(
|
423
493
|
self,
|
424
494
|
object_name,
|
@@ -427,13 +497,14 @@ module GOVUKDesignSystemFormBuilder
|
|
427
497
|
value_method: value_method,
|
428
498
|
text_method: text_method,
|
429
499
|
hint_method: hint_method,
|
430
|
-
|
500
|
+
hint: hint,
|
431
501
|
legend: legend,
|
432
502
|
caption: caption,
|
433
503
|
inline: inline,
|
434
504
|
small: small,
|
435
505
|
bold_labels: bold_labels,
|
436
506
|
classes: classes,
|
507
|
+
form_group: form_group,
|
437
508
|
&block
|
438
509
|
).html
|
439
510
|
end
|
@@ -446,19 +517,27 @@ module GOVUKDesignSystemFormBuilder
|
|
446
517
|
# is set to +link_errors: true+
|
447
518
|
#
|
448
519
|
# @param attribute_name [Symbol] The name of the attribute
|
449
|
-
# @param
|
450
|
-
#
|
520
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
521
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
522
|
+
# @option hint text [String] the hint text
|
523
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
524
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
451
525
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
452
526
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
453
527
|
# @option legend text [String] the fieldset legend's text content
|
454
528
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
455
529
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
456
530
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
531
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
457
532
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
458
533
|
# @option caption text [String] the caption text
|
459
534
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
535
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
536
|
+
# @param form_group [Hash] configures the form group
|
537
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
538
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
460
539
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
461
|
-
# @param classes [String] Classes to add to the radio button container.
|
540
|
+
# @param classes [Array,String] Classes to add to the radio button container.
|
462
541
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
463
542
|
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
464
543
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -480,19 +559,24 @@ module GOVUKDesignSystemFormBuilder
|
|
480
559
|
# = f.govuk_radio_button :burger_id, :regular, label: { text: 'Hamburger' }, link_errors: true
|
481
560
|
# = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
|
482
561
|
#
|
483
|
-
def govuk_radio_buttons_fieldset(attribute_name,
|
484
|
-
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name,
|
562
|
+
def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, classes: nil, form_group: {}, &block)
|
563
|
+
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, inline: inline, small: small, classes: classes, form_group: form_group, &block).html
|
485
564
|
end
|
486
565
|
|
487
566
|
# Generates a radio button
|
488
567
|
#
|
489
568
|
# @note This should only be used from within a {#govuk_radio_buttons_fieldset}
|
490
569
|
# @param attribute_name [Symbol] The name of the attribute
|
491
|
-
# @param
|
492
|
-
#
|
493
|
-
# @option
|
494
|
-
# @option
|
495
|
-
# @
|
570
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
571
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
572
|
+
# @option hint text [String] the hint text
|
573
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
574
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
575
|
+
# @option label text [String] the label text
|
576
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
577
|
+
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
578
|
+
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
579
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
496
580
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
497
581
|
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
498
582
|
# @param block [Block] Any supplied HTML will be wrapped in a conditional
|
@@ -506,8 +590,8 @@ module GOVUKDesignSystemFormBuilder
|
|
506
590
|
# = f.govuk_radio_buttons_fieldset :favourite_colour do
|
507
591
|
# = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
|
508
592
|
#
|
509
|
-
def govuk_radio_button(attribute_name, value,
|
510
|
-
Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value,
|
593
|
+
def govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, &block)
|
594
|
+
Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, &block).html
|
511
595
|
end
|
512
596
|
|
513
597
|
# Inserts a text divider into a list of radio buttons
|
@@ -530,10 +614,13 @@ module GOVUKDesignSystemFormBuilder
|
|
530
614
|
# @param text_method [Symbol] The method called against each member of the collection to provide the label text
|
531
615
|
# @param hint_method [Symbol, Proc] The method called against each member of the collection to provide the hint text.
|
532
616
|
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
533
|
-
# @param
|
617
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
618
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
619
|
+
# @option hint text [String] the hint text
|
620
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
534
621
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
535
|
-
# @param classes [String] Classes to add to the checkbox container.
|
536
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
622
|
+
# @param classes [Array,String] Classes to add to the checkbox container.
|
623
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
537
624
|
# @option legend text [String] the fieldset legend's text content
|
538
625
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
539
626
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
@@ -541,6 +628,10 @@ module GOVUKDesignSystemFormBuilder
|
|
541
628
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
542
629
|
# @option caption text [String] the caption text
|
543
630
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
631
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
632
|
+
# @param form_group [Hash] configures the form group
|
633
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
634
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
544
635
|
# @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
|
545
636
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
546
637
|
#
|
@@ -557,7 +648,7 @@ module GOVUKDesignSystemFormBuilder
|
|
557
648
|
# :name,
|
558
649
|
# :description,
|
559
650
|
# legend: { text: 'What do you want in your sandwich?', size: 'm' },
|
560
|
-
#
|
651
|
+
# hint: { text: "If it isn't listed here, tough luck" },
|
561
652
|
# inline: false,
|
562
653
|
# classes: 'app-overflow-scroll',
|
563
654
|
#
|
@@ -577,7 +668,7 @@ module GOVUKDesignSystemFormBuilder
|
|
577
668
|
# :name,
|
578
669
|
# legend: -> { tag.h3('What kind of sandwich do you want?') }
|
579
670
|
#
|
580
|
-
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil,
|
671
|
+
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false, classes: nil, form_group: {}, &block)
|
581
672
|
Elements::CheckBoxes::Collection.new(
|
582
673
|
self,
|
583
674
|
object_name,
|
@@ -586,11 +677,12 @@ module GOVUKDesignSystemFormBuilder
|
|
586
677
|
value_method: value_method,
|
587
678
|
text_method: text_method,
|
588
679
|
hint_method: hint_method,
|
589
|
-
|
680
|
+
hint: hint,
|
590
681
|
legend: legend,
|
591
682
|
caption: caption,
|
592
683
|
small: small,
|
593
684
|
classes: classes,
|
685
|
+
form_group: form_group,
|
594
686
|
&block
|
595
687
|
).html
|
596
688
|
end
|
@@ -601,17 +693,25 @@ module GOVUKDesignSystemFormBuilder
|
|
601
693
|
# is set to +link_errors: true+
|
602
694
|
#
|
603
695
|
# @param attribute_name [Symbol] The name of the attribute
|
604
|
-
# @param
|
696
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
697
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
698
|
+
# @option hint text [String] the hint text
|
699
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
605
700
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
606
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
701
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
607
702
|
# @option legend text [String] the fieldset legend's text content
|
608
703
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
609
704
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
610
705
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
706
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
611
707
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
612
708
|
# @option caption text [String] the caption text
|
613
709
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
614
|
-
# @
|
710
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
711
|
+
# @param classes [Array,String] Classes to add to the checkbox container.
|
712
|
+
# @param form_group [Hash] configures the form group
|
713
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
714
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
615
715
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
616
716
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
617
717
|
#
|
@@ -625,16 +725,17 @@ module GOVUKDesignSystemFormBuilder
|
|
625
725
|
# = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
|
626
726
|
# = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
|
627
727
|
#
|
628
|
-
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {},
|
728
|
+
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, classes: nil, form_group: {}, &block)
|
629
729
|
Containers::CheckBoxesFieldset.new(
|
630
730
|
self,
|
631
731
|
object_name,
|
632
732
|
attribute_name,
|
633
|
-
|
733
|
+
hint: hint,
|
634
734
|
legend: legend,
|
635
735
|
caption: caption,
|
636
736
|
small: small,
|
637
737
|
classes: classes,
|
738
|
+
form_group: form_group,
|
638
739
|
&block
|
639
740
|
).html
|
640
741
|
end
|
@@ -643,12 +744,16 @@ module GOVUKDesignSystemFormBuilder
|
|
643
744
|
#
|
644
745
|
# @param attribute_name [Symbol] The name of the attribute
|
645
746
|
# @param value [Boolean,String,Symbol,Integer] The value of the checkbox when it is checked
|
646
|
-
# @param
|
747
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
748
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
749
|
+
# @option hint text [String] the hint text
|
750
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
647
751
|
# @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
|
648
752
|
# @option label text [String] the label text
|
649
753
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
650
754
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
651
755
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
756
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
652
757
|
# @param multiple [Boolean] controls whether the check box is part of a collection or represents a single attribute
|
653
758
|
# @param block [Block] any HTML passed in will form the contents of the fieldset
|
654
759
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -659,15 +764,15 @@ module GOVUKDesignSystemFormBuilder
|
|
659
764
|
# multiple: false,
|
660
765
|
# link_errors: true,
|
661
766
|
# label: { text: 'Do you agree with our terms and conditions?' },
|
662
|
-
#
|
767
|
+
# hint: { text: 'You will not be able to proceed unless you do' }
|
663
768
|
#
|
664
|
-
def govuk_check_box(attribute_name, value,
|
769
|
+
def govuk_check_box(attribute_name, value, hint: {}, label: {}, link_errors: false, multiple: true, &block)
|
665
770
|
Elements::CheckBoxes::FieldsetCheckBox.new(
|
666
771
|
self,
|
667
772
|
object_name,
|
668
773
|
attribute_name,
|
669
774
|
value,
|
670
|
-
|
775
|
+
hint: hint,
|
671
776
|
label: label,
|
672
777
|
link_errors: link_errors,
|
673
778
|
multiple: multiple,
|
@@ -680,7 +785,7 @@ module GOVUKDesignSystemFormBuilder
|
|
680
785
|
# @param text [String] the button text
|
681
786
|
# @param warning [Boolean] makes the button red ({https://design-system.service.gov.uk/components/button/#warning-buttons warning}) when true
|
682
787
|
# @param secondary [Boolean] makes the button grey ({https://design-system.service.gov.uk/components/button/#secondary-buttons secondary}) when true
|
683
|
-
# @param classes [String] Classes to add to the submit button
|
788
|
+
# @param classes [Array,String] Classes to add to the submit button
|
684
789
|
# @param prevent_double_click [Boolean] adds JavaScript to safeguard the
|
685
790
|
# form from being submitted more than once
|
686
791
|
# @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
|
@@ -711,16 +816,24 @@ module GOVUKDesignSystemFormBuilder
|
|
711
816
|
# of {https://bugs.ruby-lang.org/issues/5988 this} bug, so incorrect dates like +2019-09-31+ will
|
712
817
|
# be 'rounded' up to +2019-10-01+.
|
713
818
|
# @param attribute_name [Symbol] The name of the attribute
|
714
|
-
# @param
|
715
|
-
#
|
819
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
820
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
821
|
+
# @option hint text [String] the hint text
|
822
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
823
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
716
824
|
# @option legend text [String] the fieldset legend's text content
|
717
825
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
718
826
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
719
827
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
828
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
720
829
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
721
830
|
# @option caption text [String] the caption text
|
722
831
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
832
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
723
833
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
834
|
+
# @param form_group [Hash] configures the form group
|
835
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
836
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
724
837
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
725
838
|
# @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
|
726
839
|
# will be added to the inputs
|
@@ -732,7 +845,7 @@ module GOVUKDesignSystemFormBuilder
|
|
732
845
|
# @example A regular date input with a legend, hint and injected content
|
733
846
|
# = f.govuk_date_field :starts_on,
|
734
847
|
# legend: { 'When does your event start?' },
|
735
|
-
#
|
848
|
+
# hint: { text: 'Leave this field blank if you don't know exactly' } do
|
736
849
|
#
|
737
850
|
# p.govuk-inset-text
|
738
851
|
# | If you don't fill this in you won't be eligable for a refund
|
@@ -740,8 +853,8 @@ module GOVUKDesignSystemFormBuilder
|
|
740
853
|
# @example A date input with legend supplied as a proc
|
741
854
|
# = f.govuk_date_field :finishes_on,
|
742
855
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
743
|
-
def govuk_date_field(attribute_name,
|
744
|
-
Elements::Date.new(self, object_name, attribute_name,
|
856
|
+
def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, &block)
|
857
|
+
Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group: form_group, &block).html
|
745
858
|
end
|
746
859
|
|
747
860
|
# Generates a summary of errors in the form, each linking to the corresponding
|
@@ -759,15 +872,17 @@ module GOVUKDesignSystemFormBuilder
|
|
759
872
|
|
760
873
|
# Generates a fieldset containing the contents of the block
|
761
874
|
#
|
762
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
875
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
763
876
|
# @param described_by [Array<String>] the ids of the elements that describe this fieldset, usually hints and errors
|
764
877
|
# @option legend text [String] the fieldset legend's text content
|
765
878
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
766
879
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
767
880
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
881
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
768
882
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
769
883
|
# @option caption text [String] the caption text
|
770
884
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
885
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
771
886
|
#
|
772
887
|
# @example A fieldset containing address fields
|
773
888
|
# = f.govuk_fieldset legend: { text: 'Address' }
|
@@ -794,11 +909,19 @@ module GOVUKDesignSystemFormBuilder
|
|
794
909
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
795
910
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
796
911
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
912
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
797
913
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
798
914
|
# @option caption text [String] the caption text
|
799
915
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
800
|
-
# @
|
801
|
-
# @
|
916
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
917
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
918
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
919
|
+
# @option hint text [String] the hint text
|
920
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
921
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
922
|
+
# @param form_group [Hash] configures the form group
|
923
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
924
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
802
925
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
803
926
|
#
|
804
927
|
# @example A photo upload field with file type specifier and injected content
|
@@ -817,8 +940,8 @@ module GOVUKDesignSystemFormBuilder
|
|
817
940
|
# @note Remember to set +multipart: true+ when creating a form with file
|
818
941
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
819
942
|
# the Rails documentation} for more information
|
820
|
-
def govuk_file_field(attribute_name, label: {}, caption: {},
|
821
|
-
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption,
|
943
|
+
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
|
944
|
+
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **kwargs, &block).html
|
822
945
|
end
|
823
946
|
end
|
824
947
|
end
|