govuk_design_system_formbuilder 0.9.8 → 2.0.0
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 +40 -35
- data/lib/govuk_design_system_formbuilder/base.rb +21 -46
- data/lib/govuk_design_system_formbuilder/builder.rb +528 -111
- data/lib/govuk_design_system_formbuilder/containers/character_count.rb +8 -7
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +20 -8
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +39 -14
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +21 -25
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +20 -9
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +28 -14
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +27 -10
- data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +8 -9
- data/lib/govuk_design_system_formbuilder/elements/caption.rb +41 -0
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +34 -22
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +28 -18
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +47 -40
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb +9 -3
- data/lib/govuk_design_system_formbuilder/elements/date.rb +65 -53
- data/lib/govuk_design_system_formbuilder/elements/error_message.rb +13 -8
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +30 -31
- data/lib/govuk_design_system_formbuilder/elements/file.rb +31 -24
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +50 -14
- data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +8 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +17 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/label.rb +63 -34
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +87 -0
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +51 -35
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +41 -19
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +37 -24
- data/lib/govuk_design_system_formbuilder/elements/select.rb +34 -32
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +39 -29
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +76 -32
- data/lib/govuk_design_system_formbuilder/traits/caption.rb +15 -0
- data/lib/govuk_design_system_formbuilder/traits/collection_item.rb +16 -0
- data/lib/govuk_design_system_formbuilder/traits/conditional.rb +17 -0
- data/lib/govuk_design_system_formbuilder/traits/error.rb +17 -0
- data/lib/govuk_design_system_formbuilder/traits/hint.rb +30 -0
- data/lib/govuk_design_system_formbuilder/traits/input.rb +105 -0
- data/lib/govuk_design_system_formbuilder/traits/label.rb +22 -0
- data/lib/govuk_design_system_formbuilder/traits/localisation.rb +51 -0
- data/lib/govuk_design_system_formbuilder/traits/supplemental.rb +17 -0
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- data/lib/govuk_design_system_formbuilder.rb +89 -44
- metadata +62 -52
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/hint.rb +0 -30
- data/lib/govuk_design_system_formbuilder/elements/inputs/base.rb +0 -79
|
@@ -1,123 +1,294 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Builder
|
|
3
|
+
delegate :config, to: GOVUKDesignSystemFormBuilder
|
|
4
|
+
|
|
3
5
|
# Generates a input of type +text+
|
|
4
6
|
#
|
|
5
7
|
# @param attribute_name [Symbol] The name of the attribute
|
|
6
|
-
# @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
|
+
#
|
|
7
13
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
|
8
14
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
9
|
-
# @param [Hash]
|
|
15
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
|
10
16
|
# @option label text [String] the label text
|
|
11
17
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
12
18
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
13
19
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
14
|
-
# @option
|
|
20
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
21
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
22
|
+
# @option caption text [String] the caption text
|
|
23
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
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
|
|
29
|
+
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
30
|
+
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
15
31
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
16
32
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
17
33
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
34
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
18
35
|
#
|
|
19
36
|
# @example A required full name field with a placeholder
|
|
20
37
|
# = f.govuk_text_field :name,
|
|
21
38
|
# label: { text: 'Full name' },
|
|
22
|
-
#
|
|
39
|
+
# hint: { text: 'It says it on your birth certificate' },
|
|
23
40
|
# required: true,
|
|
24
41
|
# placeholder: 'Ralph Wiggum'
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
#
|
|
43
|
+
# @example A text field with injected content
|
|
44
|
+
# = f.govuk_text_field :pseudonym,
|
|
45
|
+
# label: { text: 'Pseudonym' } do
|
|
46
|
+
#
|
|
47
|
+
# p.govuk-inset-text
|
|
48
|
+
# | Ensure your stage name is unique
|
|
49
|
+
#
|
|
50
|
+
# @example A text field with the label supplied as a proc
|
|
51
|
+
# = f.govuk_text_field :callsign,
|
|
52
|
+
# label: -> { tag.h3('Call-sign') }
|
|
53
|
+
#
|
|
54
|
+
def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
|
|
55
|
+
Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
|
|
27
56
|
end
|
|
28
57
|
|
|
29
58
|
# Generates a input of type +tel+
|
|
30
59
|
#
|
|
31
60
|
# @param attribute_name [Symbol] The name of the attribute
|
|
32
|
-
# @param
|
|
61
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
62
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
63
|
+
# @option hint text [String] the hint text
|
|
64
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
33
65
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
|
34
66
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
35
|
-
# @param [Hash]
|
|
67
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
|
36
68
|
# @option label text [String] the label text
|
|
37
69
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
38
70
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
39
71
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
40
|
-
# @option
|
|
72
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
73
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
74
|
+
# @option caption text [String] the caption text
|
|
75
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
76
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
77
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
78
|
+
# @param form_group [Hash] configures the form group
|
|
79
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
80
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
81
|
+
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
82
|
+
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
41
83
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
42
84
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
43
85
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
44
86
|
# @see https://design-system.service.gov.uk/patterns/telephone-numbers/ GOV.UK Telephone number patterns
|
|
87
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
45
88
|
#
|
|
46
89
|
# @example A required phone number field with a placeholder
|
|
47
90
|
# = f.govuk_phone_field :phone_number,
|
|
48
91
|
# label: { text: 'UK telephone number' },
|
|
49
|
-
#
|
|
92
|
+
# hint: { text: 'Include the dialling code' },
|
|
50
93
|
# required: true,
|
|
51
94
|
# placeholder: '0123 456 789'
|
|
52
|
-
|
|
53
|
-
|
|
95
|
+
#
|
|
96
|
+
# @example A phone field with injected content
|
|
97
|
+
# = f.govuk_phone_field :fax_number,
|
|
98
|
+
# label: { text: 'Fax number' } do
|
|
99
|
+
#
|
|
100
|
+
# p.govuk-inset-text
|
|
101
|
+
# | Yes, fax machines are still a thing
|
|
102
|
+
#
|
|
103
|
+
# @example A phone field with the label supplied as a proc
|
|
104
|
+
# = f.govuk_phone_field :work_number,
|
|
105
|
+
# label: -> { tag.h3('Work number') }
|
|
106
|
+
#
|
|
107
|
+
def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
|
|
108
|
+
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
|
|
54
109
|
end
|
|
55
110
|
|
|
56
111
|
# Generates a input of type +email+
|
|
57
112
|
#
|
|
58
113
|
# @param attribute_name [Symbol] The name of the attribute
|
|
59
|
-
# @param
|
|
114
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
115
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
116
|
+
# @option hint text [String] the hint text
|
|
117
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
60
118
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
|
61
119
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
62
|
-
# @param [Hash]
|
|
120
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
|
63
121
|
# @option label text [String] the label text
|
|
64
122
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
65
123
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
66
124
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
67
|
-
# @option
|
|
125
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
126
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
127
|
+
# @option caption text [String] the caption text
|
|
128
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
129
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
130
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
131
|
+
# @param form_group [Hash] configures the form group
|
|
132
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
133
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
134
|
+
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
135
|
+
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
68
136
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
69
137
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
70
138
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
71
139
|
# @see https://design-system.service.gov.uk/patterns/email-addresses/ GOV.UK Email address patterns
|
|
140
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
72
141
|
#
|
|
73
142
|
# @example An email address field with a placeholder
|
|
74
143
|
# = f.govuk_email_field :email_address,
|
|
75
144
|
# label: { text: 'Enter your email address' },
|
|
76
145
|
# placeholder: 'ralph.wiggum@springfield.edu'
|
|
77
|
-
|
|
78
|
-
|
|
146
|
+
#
|
|
147
|
+
# @example An email field with injected content
|
|
148
|
+
# = f.govuk_phone_field :work_email,
|
|
149
|
+
# label: { text: 'Work email address' } do
|
|
150
|
+
#
|
|
151
|
+
# p.govuk-inset-text
|
|
152
|
+
# | Use your work address
|
|
153
|
+
#
|
|
154
|
+
# @example A email field with the label supplied as a proc
|
|
155
|
+
# = f.govuk_email_field :personal_email,
|
|
156
|
+
# label: -> { tag.h3('Personal email address') }
|
|
157
|
+
#
|
|
158
|
+
def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
|
|
159
|
+
Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Generates a input of type +password+
|
|
163
|
+
#
|
|
164
|
+
# @param attribute_name [Symbol] The name of the attribute
|
|
165
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
166
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
167
|
+
# @option hint text [String] the hint text
|
|
168
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
169
|
+
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
|
170
|
+
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
171
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
|
172
|
+
# @option label text [String] the label text
|
|
173
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
174
|
+
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
175
|
+
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
176
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
177
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
178
|
+
# @option caption text [String] the caption text
|
|
179
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
180
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
181
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
182
|
+
# @param form_group [Hash] configures the form group
|
|
183
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
184
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
185
|
+
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
186
|
+
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
187
|
+
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
188
|
+
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
189
|
+
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
190
|
+
# @see https://design-system.service.gov.uk/patterns/passwords/ GOV.UK Password patterns
|
|
191
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
192
|
+
#
|
|
193
|
+
# @example A password field
|
|
194
|
+
# = f.govuk_password_field :password,
|
|
195
|
+
# label: { text: 'Enter your password' }
|
|
196
|
+
#
|
|
197
|
+
# @example A password field with injected content
|
|
198
|
+
# = f.govuk_password_field :password,
|
|
199
|
+
# label: { text: 'Password' } do
|
|
200
|
+
#
|
|
201
|
+
# p.govuk-inset-text
|
|
202
|
+
# | Ensure your password is at least 16 characters long
|
|
203
|
+
#
|
|
204
|
+
# @example A password field with the label supplied as a proc
|
|
205
|
+
# = f.govuk_password_field :passcode,
|
|
206
|
+
# label: -> { tag.h3('What is your secret pass code?') }
|
|
207
|
+
#
|
|
208
|
+
def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, form_group: {}, caption: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
|
|
209
|
+
Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
|
|
79
210
|
end
|
|
80
211
|
|
|
81
212
|
# Generates a input of type +url+
|
|
82
213
|
#
|
|
83
214
|
# @param attribute_name [Symbol] The name of the attribute
|
|
84
|
-
# @param
|
|
215
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
216
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
217
|
+
# @option hint text [String] the hint text
|
|
218
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
85
219
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
|
86
220
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
87
|
-
# @param [Hash]
|
|
221
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
|
88
222
|
# @option label text [String] the label text
|
|
89
223
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
90
224
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
91
225
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
92
|
-
# @option
|
|
226
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
227
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
228
|
+
# @option caption text [String] the caption text
|
|
229
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
230
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
231
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
232
|
+
# @param form_group [Hash] configures the form group
|
|
233
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
234
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
235
|
+
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
236
|
+
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
93
237
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
94
238
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
95
239
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
240
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
96
241
|
#
|
|
97
242
|
# @example A url field with autocomplete
|
|
98
243
|
# = f.govuk_url_field :favourite_website,
|
|
99
244
|
# label: { text: 'Enter your favourite website' },
|
|
100
245
|
# placeholder: 'https://www.gov.uk',
|
|
101
246
|
# autocomplete: 'url'
|
|
102
|
-
|
|
103
|
-
|
|
247
|
+
#
|
|
248
|
+
# @example A url field with injected content
|
|
249
|
+
# = f.govuk_url_field :personal_website,
|
|
250
|
+
# label: { text: 'Enter your website' } do
|
|
251
|
+
#
|
|
252
|
+
# p.govuk-inset-text
|
|
253
|
+
# | This will be visible on your profile
|
|
254
|
+
#
|
|
255
|
+
# @example A url field with the label supplied as a proc
|
|
256
|
+
# = f.govuk_url_field :work_website,
|
|
257
|
+
# label: -> { tag.h3("Enter your company's website") }
|
|
258
|
+
#
|
|
259
|
+
def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
|
|
260
|
+
Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
|
|
104
261
|
end
|
|
105
262
|
|
|
106
263
|
# Generates a input of type +number+
|
|
107
264
|
#
|
|
108
265
|
# @param attribute_name [Symbol] The name of the attribute
|
|
109
|
-
# @param
|
|
266
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
267
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
268
|
+
# @option hint text [String] the hint text
|
|
269
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
110
270
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
|
111
271
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
|
112
|
-
# @param [Hash]
|
|
272
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
|
113
273
|
# @option label text [String] the label text
|
|
114
274
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
115
275
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
116
276
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
117
|
-
# @option
|
|
277
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
278
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
279
|
+
# @option caption text [String] the caption text
|
|
280
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
281
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
282
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
283
|
+
# @param form_group [Hash] configures the form group
|
|
284
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
285
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
286
|
+
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
287
|
+
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
118
288
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
119
289
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
120
290
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
|
291
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
121
292
|
#
|
|
122
293
|
# @example A number field with placeholder, min, max and step
|
|
123
294
|
# = f.govuk_number_field :iq,
|
|
@@ -126,8 +297,21 @@ module GOVUKDesignSystemFormBuilder
|
|
|
126
297
|
# min: 80,
|
|
127
298
|
# max: 150,
|
|
128
299
|
# step: 5
|
|
129
|
-
|
|
130
|
-
|
|
300
|
+
#
|
|
301
|
+
# @example A number field with injected content
|
|
302
|
+
# = f.govuk_number_field :height_in_cm,
|
|
303
|
+
# label: { text: 'Height in centimetres' } do
|
|
304
|
+
#
|
|
305
|
+
# p.govuk-inset-text
|
|
306
|
+
# | If you haven't measured your height in the last 6 months
|
|
307
|
+
# do it now
|
|
308
|
+
#
|
|
309
|
+
# @example A number field with the label supplied as a proc
|
|
310
|
+
# = f.govuk_url_field :personal_best_over_100m,
|
|
311
|
+
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
|
|
312
|
+
#
|
|
313
|
+
def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
|
|
314
|
+
Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, prefix_text: prefix_text, suffix_text: suffix_text, **kwargs, &block).html
|
|
131
315
|
end
|
|
132
316
|
|
|
133
317
|
# Generates a +textarea+ element with a label, optional hint. Also offers
|
|
@@ -135,30 +319,55 @@ module GOVUKDesignSystemFormBuilder
|
|
|
135
319
|
# automatically
|
|
136
320
|
#
|
|
137
321
|
# @param attribute_name [Symbol] The name of the attribute
|
|
138
|
-
# @param
|
|
139
|
-
#
|
|
322
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
323
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
324
|
+
# @option hint text [String] the hint text
|
|
325
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
326
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
|
140
327
|
# @option label text [String] the label text
|
|
141
328
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
142
329
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
143
330
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
331
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
332
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
333
|
+
# @option caption text [String] the caption text
|
|
334
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
335
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
144
336
|
# @param max_words [Integer] adds the GOV.UK max word count
|
|
145
337
|
# @param max_chars [Integer] adds the GOV.UK max characters count
|
|
146
338
|
# @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
|
|
147
339
|
# @param rows [Integer] sets the initial number of rows
|
|
148
|
-
# @option
|
|
340
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +textarea+ element
|
|
341
|
+
# @param form_group [Hash] configures the form group
|
|
342
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
343
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
149
344
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
150
345
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
346
|
+
# @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
|
|
151
347
|
# @see https://design-system.service.gov.uk/components/character-count GOV.UK character count component
|
|
348
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
152
349
|
# @note Setting +max_chars+ or +max_words+ will add a caption beneath the +textarea+ with a live count of words
|
|
153
350
|
# or characters
|
|
154
351
|
#
|
|
155
352
|
# @example A text area with a custom number of rows and a word limit
|
|
156
|
-
# = f.
|
|
353
|
+
# = f.govuk_text_area :cv,
|
|
157
354
|
# label: { text: 'Tell us about your work history' },
|
|
158
355
|
# rows: 8,
|
|
159
356
|
# max_words: 300
|
|
160
|
-
|
|
161
|
-
|
|
357
|
+
#
|
|
358
|
+
# @example A text area with injected content
|
|
359
|
+
# = f.govuk_text_area :description,
|
|
360
|
+
# label: { text: 'Where did the incident take place?' } do
|
|
361
|
+
#
|
|
362
|
+
# p.govuk-inset-text
|
|
363
|
+
# | If you don't know exactly leave this section blank
|
|
364
|
+
#
|
|
365
|
+
# @example A text area with the label supplied as a proc
|
|
366
|
+
# = f.govuk_text_area :instructions,
|
|
367
|
+
# label: -> { tag.h3("How do you set it up?") }
|
|
368
|
+
#
|
|
369
|
+
def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block)
|
|
370
|
+
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
|
|
162
371
|
end
|
|
163
372
|
|
|
164
373
|
# Generates a +select+ element containing +option+ for each member in the provided collection
|
|
@@ -167,14 +376,42 @@ module GOVUKDesignSystemFormBuilder
|
|
|
167
376
|
# @param collection [Enumerable<Object>] Options to be added to the +select+ element
|
|
168
377
|
# @param value_method [Symbol] The method called against each member of the collection to provide the value
|
|
169
378
|
# @param text_method [Symbol] The method called against each member of the collection to provide the text
|
|
170
|
-
# @param
|
|
379
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
380
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
381
|
+
# @option hint text [String] the hint text
|
|
382
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
171
383
|
# @option label text [String] the label text
|
|
172
384
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
173
385
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
174
386
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
387
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
388
|
+
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
|
389
|
+
# @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
|
|
390
|
+
# @param form_group [Hash] configures the form group
|
|
391
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
392
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
175
393
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
394
|
+
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
|
176
395
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
177
|
-
|
|
396
|
+
#
|
|
397
|
+
# @example A select box with hint
|
|
398
|
+
# = f.govuk_collection_select :grade,
|
|
399
|
+
# @grades,
|
|
400
|
+
# :id,
|
|
401
|
+
# :name,
|
|
402
|
+
# hint: { text: "If you took the test more than once enter your highest grade" }
|
|
403
|
+
#
|
|
404
|
+
# @example A select box with injected content
|
|
405
|
+
# = f.govuk_collection_select(:favourite_colour, @colours, :id, :name) do
|
|
406
|
+
#
|
|
407
|
+
# p.govuk-inset-text
|
|
408
|
+
# | Select the closest match
|
|
409
|
+
#
|
|
410
|
+
# @example A select box with the label supplied as a proc
|
|
411
|
+
# = f.govuk_collection_select(:team, @teams, :id, :name) do
|
|
412
|
+
# label: -> { tag.h3("Which team did you represent?") }
|
|
413
|
+
#
|
|
414
|
+
def govuk_collection_select(attribute_name, collection, value_method, text_method, options: {}, html_options: {}, hint: {}, label: {}, caption: {}, form_group: {}, &block)
|
|
178
415
|
Elements::Select.new(
|
|
179
416
|
self,
|
|
180
417
|
object_name,
|
|
@@ -182,10 +419,12 @@ module GOVUKDesignSystemFormBuilder
|
|
|
182
419
|
collection,
|
|
183
420
|
value_method: value_method,
|
|
184
421
|
text_method: text_method,
|
|
185
|
-
|
|
422
|
+
hint: hint,
|
|
186
423
|
label: label,
|
|
424
|
+
caption: caption,
|
|
187
425
|
options: options,
|
|
188
426
|
html_options: html_options,
|
|
427
|
+
form_group: form_group,
|
|
189
428
|
&block
|
|
190
429
|
).html
|
|
191
430
|
end
|
|
@@ -201,20 +440,35 @@ module GOVUKDesignSystemFormBuilder
|
|
|
201
440
|
#
|
|
202
441
|
# @param attribute_name [Symbol] The name of the attribute
|
|
203
442
|
# @param collection [Enumerable<Object>] Options to be added to the +select+ element
|
|
204
|
-
# @param value_method [Symbol] The method called against each member of the collection to provide the value
|
|
205
|
-
#
|
|
206
|
-
# @param
|
|
207
|
-
#
|
|
208
|
-
#
|
|
443
|
+
# @param value_method [Symbol, Proc] The method called against each member of the collection to provide the value.
|
|
444
|
+
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
|
445
|
+
# @param text_method [Symbol, Proc, nil] The method called against each member of the collection to provide the label text.
|
|
446
|
+
# When a +Proc+ is provided it must take a single argument that is a single member of the collection.
|
|
447
|
+
# When a +nil+ value is provided the label text will be retrieved from the locale.
|
|
448
|
+
# @param hint_method [Symbol, Proc, nil] The method called against each member of the collection to provide the hint text.
|
|
449
|
+
# When a +Proc+ is provided it must take a single argument that is a single member of the collection.
|
|
450
|
+
# When a +nil+ value is provided the hint text will be retrieved from the locale. This is the default and param can be omitted.
|
|
451
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
452
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
453
|
+
# @option hint text [String] the hint text
|
|
454
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
455
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
|
209
456
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
|
210
457
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
|
211
458
|
# @param bold_labels [Boolean] controls whether the radio button labels are bold
|
|
459
|
+
# @param classes [Array,String] Classes to add to the radio button container.
|
|
212
460
|
# @option legend text [String] the fieldset legend's text content
|
|
213
461
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
214
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
|
462
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
|
463
|
+
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
|
464
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
|
465
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
|
466
|
+
# @option caption text [String] the caption text
|
|
467
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
468
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
215
469
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
216
470
|
#
|
|
217
|
-
# @example A collection of radio buttons for favourite colours
|
|
471
|
+
# @example A collection of radio buttons for favourite colours, labels capitalised via a proc
|
|
218
472
|
#
|
|
219
473
|
# @colours = [
|
|
220
474
|
# OpenStruct.new(id: 'red', name: 'Red', description: 'Roses are red'),
|
|
@@ -224,12 +478,29 @@ module GOVUKDesignSystemFormBuilder
|
|
|
224
478
|
# = f.govuk_collection_radio_buttons :favourite_colour,
|
|
225
479
|
# @colours,
|
|
226
480
|
# :id,
|
|
227
|
-
#
|
|
481
|
+
# ->(option) { option.name.upcase },
|
|
228
482
|
# :description,
|
|
229
483
|
# legend: { text: 'Pick your favourite colour', size: 'm' },
|
|
230
|
-
#
|
|
484
|
+
# hint: { text: 'If you cannot find the exact match choose something close' },
|
|
231
485
|
# inline: false
|
|
232
|
-
|
|
486
|
+
#
|
|
487
|
+
# @example A collection of radio buttons for grades with injected content
|
|
488
|
+
# = f.govuk_collection_radio_buttons :grade,
|
|
489
|
+
# @grades,
|
|
490
|
+
# :id,
|
|
491
|
+
# :name do
|
|
492
|
+
#
|
|
493
|
+
# p.govuk-inset-text
|
|
494
|
+
# | If you took the test more than once enter your highest grade
|
|
495
|
+
#
|
|
496
|
+
# @example A collection of radio buttons with the legend supplied as a proc
|
|
497
|
+
# = f.govuk_collection_radio_buttons :category,
|
|
498
|
+
# @categories,
|
|
499
|
+
# :id,
|
|
500
|
+
# :name,
|
|
501
|
+
# legend: -> { tag.h3('Which category do you belong to?') }
|
|
502
|
+
#
|
|
503
|
+
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: false, classes: nil, form_group: {}, &block)
|
|
233
504
|
Elements::Radios::Collection.new(
|
|
234
505
|
self,
|
|
235
506
|
object_name,
|
|
@@ -238,11 +509,14 @@ module GOVUKDesignSystemFormBuilder
|
|
|
238
509
|
value_method: value_method,
|
|
239
510
|
text_method: text_method,
|
|
240
511
|
hint_method: hint_method,
|
|
241
|
-
|
|
512
|
+
hint: hint,
|
|
242
513
|
legend: legend,
|
|
514
|
+
caption: caption,
|
|
243
515
|
inline: inline,
|
|
244
516
|
small: small,
|
|
245
517
|
bold_labels: bold_labels,
|
|
518
|
+
classes: classes,
|
|
519
|
+
form_group: form_group,
|
|
246
520
|
&block
|
|
247
521
|
).html
|
|
248
522
|
end
|
|
@@ -251,52 +525,85 @@ module GOVUKDesignSystemFormBuilder
|
|
|
251
525
|
#
|
|
252
526
|
# @note The intention is to use {#govuk_radio_button} and {#govuk_radio_divider} within the passed-in block
|
|
253
527
|
#
|
|
528
|
+
# @note To ensure the {#govuk_error_summary} link functions correctly ensure the first {#govuk_radio_button}
|
|
529
|
+
# is set to +link_errors: true+
|
|
530
|
+
#
|
|
254
531
|
# @param attribute_name [Symbol] The name of the attribute
|
|
255
|
-
# @param
|
|
256
|
-
#
|
|
532
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
533
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
534
|
+
# @option hint text [String] the hint text
|
|
535
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
536
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
|
257
537
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
|
258
538
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
|
259
539
|
# @option legend text [String] the fieldset legend's text content
|
|
260
540
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
261
541
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
|
542
|
+
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
|
543
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
|
544
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
|
545
|
+
# @option caption text [String] the caption text
|
|
546
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
547
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
548
|
+
# @param form_group [Hash] configures the form group
|
|
549
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
550
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
262
551
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
|
552
|
+
# @param classes [Array,String] Classes to add to the radio button container.
|
|
263
553
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
|
554
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
264
555
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
265
556
|
#
|
|
266
|
-
# @example A
|
|
557
|
+
# @example A radio button fieldset for favourite colours with a divider
|
|
267
558
|
#
|
|
268
|
-
# = f.
|
|
269
|
-
# = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
|
|
559
|
+
# = f.govuk_radio_buttons_fieldset :favourite_colour, inline: false do
|
|
560
|
+
# = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }, link_errors: true
|
|
270
561
|
# = f.govuk_radio_button :favourite_colour, :green, label: { text: 'Green' }
|
|
271
562
|
# = f.govuk_radio_divider
|
|
272
563
|
# = f.govuk_radio_button :favourite_colour, :yellow, label: { text: 'Yellow' }
|
|
273
564
|
#
|
|
274
|
-
|
|
275
|
-
|
|
565
|
+
# @example A radio button fieldset with the legend supplied as a proc
|
|
566
|
+
# = f.govuk_radio_buttons_fieldset :burger_id do
|
|
567
|
+
# @burgers,
|
|
568
|
+
# :id,
|
|
569
|
+
# :name,
|
|
570
|
+
# legend: -> { tag.h3('Which hamburger do you want with your meal?') } do
|
|
571
|
+
# = f.govuk_radio_button :burger_id, :regular, label: { text: 'Hamburger' }, link_errors: true
|
|
572
|
+
# = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
|
|
573
|
+
#
|
|
574
|
+
def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, classes: nil, form_group: {}, &block)
|
|
575
|
+
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
|
|
276
576
|
end
|
|
277
577
|
|
|
278
578
|
# Generates a radio button
|
|
279
579
|
#
|
|
280
580
|
# @note This should only be used from within a {#govuk_radio_buttons_fieldset}
|
|
281
581
|
# @param attribute_name [Symbol] The name of the attribute
|
|
282
|
-
# @param
|
|
283
|
-
#
|
|
284
|
-
# @option
|
|
285
|
-
# @option
|
|
582
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
583
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
584
|
+
# @option hint text [String] the hint text
|
|
585
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
586
|
+
# @param label [Hash,Proc] configures or sets the associated label content
|
|
587
|
+
# @option label text [String] the label text
|
|
588
|
+
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
589
|
+
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
590
|
+
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
591
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
286
592
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
|
593
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
287
594
|
# @param block [Block] Any supplied HTML will be wrapped in a conditional
|
|
288
595
|
# container and only revealed when the radio button is picked
|
|
289
|
-
# @param link_errors [Boolean] controls whether this radio button should be linked to
|
|
596
|
+
# @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
|
|
290
597
|
# from the error summary. <b>Should only be set to +true+ for the first radio button in a fieldset</b>
|
|
291
598
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
292
599
|
#
|
|
293
|
-
# @example A
|
|
600
|
+
# @example A single radio button for our new favourite colour
|
|
294
601
|
#
|
|
295
|
-
# = f.
|
|
296
|
-
# = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
|
|
602
|
+
# = f.govuk_radio_buttons_fieldset :favourite_colour do
|
|
603
|
+
# = f.govuk_radio_button :favourite_colour, :red, label: { text: 'Red' }
|
|
297
604
|
#
|
|
298
|
-
def govuk_radio_button(attribute_name, value,
|
|
299
|
-
Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value,
|
|
605
|
+
def govuk_radio_button(attribute_name, value, hint: {}, label: {}, link_errors: false, &block)
|
|
606
|
+
Elements::Radios::FieldsetRadioButton.new(self, object_name, attribute_name, value, hint: hint, label: label, link_errors: link_errors, &block).html
|
|
300
607
|
end
|
|
301
608
|
|
|
302
609
|
# Inserts a text divider into a list of radio buttons
|
|
@@ -307,7 +614,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
307
614
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
308
615
|
# @example A custom divider
|
|
309
616
|
# = govuk_radio_divider 'Alternatively'
|
|
310
|
-
def govuk_radio_divider(text =
|
|
617
|
+
def govuk_radio_divider(text = config.default_radio_divider_text)
|
|
311
618
|
tag.div(text, class: %w(govuk-radios__divider))
|
|
312
619
|
end
|
|
313
620
|
|
|
@@ -316,14 +623,27 @@ module GOVUKDesignSystemFormBuilder
|
|
|
316
623
|
# @param attribute_name [Symbol] The name of the attribute
|
|
317
624
|
# @param collection [Enumerable<Object>] Options to be added to the +select+ element
|
|
318
625
|
# @param value_method [Symbol] The method called against each member of the collection to provide the value
|
|
319
|
-
# @param text_method [Symbol] The method called against each member of the collection to provide the text
|
|
320
|
-
# @param hint_method [Symbol] The method called against each member of the collection to provide the hint text
|
|
321
|
-
#
|
|
626
|
+
# @param text_method [Symbol] The method called against each member of the collection to provide the label text
|
|
627
|
+
# @param hint_method [Symbol, Proc] The method called against each member of the collection to provide the hint text.
|
|
628
|
+
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
|
629
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
630
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
631
|
+
# @option hint text [String] the hint text
|
|
632
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
322
633
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
|
323
|
-
# @param
|
|
634
|
+
# @param classes [Array,String] Classes to add to the checkbox container.
|
|
635
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
|
324
636
|
# @option legend text [String] the fieldset legend's text content
|
|
325
637
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
326
638
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
|
639
|
+
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
|
640
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
|
641
|
+
# @option caption text [String] the caption text
|
|
642
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
643
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
644
|
+
# @param form_group [Hash] configures the form group
|
|
645
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
646
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
327
647
|
# @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
|
|
328
648
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
329
649
|
#
|
|
@@ -340,9 +660,27 @@ module GOVUKDesignSystemFormBuilder
|
|
|
340
660
|
# :name,
|
|
341
661
|
# :description,
|
|
342
662
|
# legend: { text: 'What do you want in your sandwich?', size: 'm' },
|
|
343
|
-
#
|
|
344
|
-
# inline: false
|
|
345
|
-
|
|
663
|
+
# hint: { text: "If it isn't listed here, tough luck" },
|
|
664
|
+
# inline: false,
|
|
665
|
+
# classes: 'app-overflow-scroll',
|
|
666
|
+
#
|
|
667
|
+
# @example A collection of check boxes for types of bread
|
|
668
|
+
# = f.govuk_collection_check_boxes :bread,
|
|
669
|
+
# @variety,
|
|
670
|
+
# :id,
|
|
671
|
+
# :name do
|
|
672
|
+
#
|
|
673
|
+
# p.govuk-inset-text
|
|
674
|
+
# | Only Hearty Italian is available with the meal deal menu
|
|
675
|
+
#
|
|
676
|
+
# @example A collection of check boxes with the legend supplied as a proc
|
|
677
|
+
# = f.govuk_collection_check_boxes :sandwich_type,
|
|
678
|
+
# @breads,
|
|
679
|
+
# :id,
|
|
680
|
+
# :name,
|
|
681
|
+
# legend: -> { tag.h3('What kind of sandwich do you want?') }
|
|
682
|
+
#
|
|
683
|
+
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)
|
|
346
684
|
Elements::CheckBoxes::Collection.new(
|
|
347
685
|
self,
|
|
348
686
|
object_name,
|
|
@@ -351,53 +689,87 @@ module GOVUKDesignSystemFormBuilder
|
|
|
351
689
|
value_method: value_method,
|
|
352
690
|
text_method: text_method,
|
|
353
691
|
hint_method: hint_method,
|
|
354
|
-
|
|
692
|
+
hint: hint,
|
|
355
693
|
legend: legend,
|
|
694
|
+
caption: caption,
|
|
356
695
|
small: small,
|
|
696
|
+
classes: classes,
|
|
697
|
+
form_group: form_group,
|
|
357
698
|
&block
|
|
358
699
|
).html
|
|
359
700
|
end
|
|
360
701
|
|
|
361
702
|
# Generate a fieldset intended to conatain one or more {#govuk_check_box}
|
|
362
703
|
#
|
|
704
|
+
# @note To ensure the {#govuk_error_summary} link functions correctly ensure the first {#govuk_check_box}
|
|
705
|
+
# is set to +link_errors: true+
|
|
706
|
+
#
|
|
363
707
|
# @param attribute_name [Symbol] The name of the attribute
|
|
364
|
-
# @param
|
|
708
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
709
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
710
|
+
# @option hint text [String] the hint text
|
|
711
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
365
712
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
|
366
|
-
# @param legend [Hash] options for configuring the legend
|
|
713
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
|
367
714
|
# @option legend text [String] the fieldset legend's text content
|
|
368
715
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
369
716
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
|
717
|
+
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
|
718
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
|
719
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
|
720
|
+
# @option caption text [String] the caption text
|
|
721
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
722
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
723
|
+
# @param classes [Array,String] Classes to add to the checkbox container.
|
|
724
|
+
# @param form_group [Hash] configures the form group
|
|
725
|
+
# @param multiple [Boolean] when true adds a +[]+ suffix the +name+ of the automatically-generated hidden field
|
|
726
|
+
# (ie. <code>project[invoice_attributes][]</code>). When false, no +[]+ suffix is added (ie. <code>project[accepted]</code>)
|
|
727
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
728
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
370
729
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
|
371
730
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
372
731
|
#
|
|
373
732
|
# @example A collection of check boxes for sandwich fillings
|
|
374
|
-
#
|
|
375
|
-
# = f.govuk_check_boxes_fieldset :desired_filling,
|
|
733
|
+
# = f.govuk_check_boxes_fieldset :desired_filling, legend: { text: 'Which filling do you want?' },
|
|
376
734
|
# = f.govuk_check_box :desired_filling, :cheese, label: { text: 'Cheese' }, link_errors: true
|
|
377
735
|
# = f.govuk_check_box :desired_filling, :tomato, label: { text: 'Tomato' }
|
|
378
736
|
#
|
|
379
|
-
|
|
737
|
+
# @example A collection of check boxes for drinks choices with legend as a proc
|
|
738
|
+
# = f.govuk_check_boxes_fieldset :drink_id, legend: -> { tag.h3('Choose drinks to accompany your meal') },
|
|
739
|
+
# = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
|
|
740
|
+
# = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
|
|
741
|
+
#
|
|
742
|
+
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, classes: nil, form_group: {}, multiple: true, &block)
|
|
380
743
|
Containers::CheckBoxesFieldset.new(
|
|
381
744
|
self,
|
|
382
745
|
object_name,
|
|
383
746
|
attribute_name,
|
|
384
|
-
|
|
747
|
+
hint: hint,
|
|
385
748
|
legend: legend,
|
|
749
|
+
caption: caption,
|
|
386
750
|
small: small,
|
|
751
|
+
classes: classes,
|
|
752
|
+
form_group: form_group,
|
|
753
|
+
multiple: multiple,
|
|
387
754
|
&block
|
|
388
755
|
).html
|
|
389
756
|
end
|
|
390
757
|
|
|
391
|
-
# Generates a single
|
|
758
|
+
# Generates a single check box, intended for use within a {#govuk_check_boxes_fieldset}
|
|
392
759
|
#
|
|
393
760
|
# @param attribute_name [Symbol] The name of the attribute
|
|
394
761
|
# @param value [Boolean,String,Symbol,Integer] The value of the checkbox when it is checked
|
|
395
|
-
# @param
|
|
396
|
-
# @param
|
|
762
|
+
# @param unchecked_value [Boolean,String,Symbol,Integer] The value of the checkbox when it is unchecked
|
|
763
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
764
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
765
|
+
# @option hint text [String] the hint text
|
|
766
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
767
|
+
# @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
|
|
397
768
|
# @option label text [String] the label text
|
|
398
769
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
399
770
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
400
771
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
772
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
401
773
|
# @param multiple [Boolean] controls whether the check box is part of a collection or represents a single attribute
|
|
402
774
|
# @param block [Block] any HTML passed in will form the contents of the fieldset
|
|
403
775
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
@@ -408,15 +780,16 @@ module GOVUKDesignSystemFormBuilder
|
|
|
408
780
|
# multiple: false,
|
|
409
781
|
# link_errors: true,
|
|
410
782
|
# label: { text: 'Do you agree with our terms and conditions?' },
|
|
411
|
-
#
|
|
783
|
+
# hint: { text: 'You will not be able to proceed unless you do' }
|
|
412
784
|
#
|
|
413
|
-
def govuk_check_box(attribute_name, value,
|
|
785
|
+
def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, &block)
|
|
414
786
|
Elements::CheckBoxes::FieldsetCheckBox.new(
|
|
415
787
|
self,
|
|
416
788
|
object_name,
|
|
417
789
|
attribute_name,
|
|
418
790
|
value,
|
|
419
|
-
|
|
791
|
+
unchecked_value,
|
|
792
|
+
hint: hint,
|
|
420
793
|
label: label,
|
|
421
794
|
link_errors: link_errors,
|
|
422
795
|
multiple: multiple,
|
|
@@ -429,13 +802,13 @@ module GOVUKDesignSystemFormBuilder
|
|
|
429
802
|
# @param text [String] the button text
|
|
430
803
|
# @param warning [Boolean] makes the button red ({https://design-system.service.gov.uk/components/button/#warning-buttons warning}) when true
|
|
431
804
|
# @param secondary [Boolean] makes the button grey ({https://design-system.service.gov.uk/components/button/#secondary-buttons secondary}) when true
|
|
432
|
-
# @
|
|
433
|
-
# should probably be supported too
|
|
805
|
+
# @param classes [Array,String] Classes to add to the submit button
|
|
434
806
|
# @param prevent_double_click [Boolean] adds JavaScript to safeguard the
|
|
435
807
|
# form from being submitted more than once
|
|
436
808
|
# @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
|
|
437
809
|
# client-side validation provided by the browser. This is to provide a more consistent and accessible user
|
|
438
810
|
# experience
|
|
811
|
+
# @param disabled [Boolean] makes the button disabled when true
|
|
439
812
|
# @param block [Block] Any supplied HTML will be inserted immediately after
|
|
440
813
|
# the submit button. It is intended for other buttons directly related to
|
|
441
814
|
# the form's operation, such as 'Cancel' or 'Safe draft'
|
|
@@ -450,8 +823,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
450
823
|
# = f.govuk_submit "Proceed", prevent_double_click: true do
|
|
451
824
|
# = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
|
|
452
825
|
#
|
|
453
|
-
def govuk_submit(text =
|
|
454
|
-
Elements::Submit.new(self, text, warning: warning, secondary: secondary, prevent_double_click: prevent_double_click, validate: validate, &block).html
|
|
826
|
+
def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, classes: nil, prevent_double_click: true, validate: false, disabled: false, &block)
|
|
827
|
+
Elements::Submit.new(self, text, warning: warning, secondary: secondary, classes: classes, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, &block).html
|
|
455
828
|
end
|
|
456
829
|
|
|
457
830
|
# Generates three inputs for the +day+, +month+ and +year+ components of a date
|
|
@@ -460,25 +833,45 @@ module GOVUKDesignSystemFormBuilder
|
|
|
460
833
|
# of {https://bugs.ruby-lang.org/issues/5988 this} bug, so incorrect dates like +2019-09-31+ will
|
|
461
834
|
# be 'rounded' up to +2019-10-01+.
|
|
462
835
|
# @param attribute_name [Symbol] The name of the attribute
|
|
463
|
-
# @param
|
|
464
|
-
#
|
|
836
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
837
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
838
|
+
# @option hint text [String] the hint text
|
|
839
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
840
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
|
465
841
|
# @option legend text [String] the fieldset legend's text content
|
|
466
842
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
467
843
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
|
844
|
+
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
|
845
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
|
846
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
|
847
|
+
# @option caption text [String] the caption text
|
|
848
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
849
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
468
850
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
|
851
|
+
# @param form_group [Hash] configures the form group
|
|
852
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
853
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
469
854
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
|
470
855
|
# @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
|
|
471
856
|
# will be added to the inputs
|
|
472
857
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
473
858
|
#
|
|
474
859
|
# @see https://github.com/alphagov/govuk-frontend/issues/1449 GOV.UK date input element attributes, using text instead of number
|
|
860
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
475
861
|
#
|
|
476
|
-
# @example A regular date input with a legend and
|
|
862
|
+
# @example A regular date input with a legend, hint and injected content
|
|
477
863
|
# = f.govuk_date_field :starts_on,
|
|
478
864
|
# legend: { 'When does your event start?' },
|
|
479
|
-
#
|
|
480
|
-
|
|
481
|
-
|
|
865
|
+
# hint: { text: 'Leave this field blank if you don't know exactly' } do
|
|
866
|
+
#
|
|
867
|
+
# p.govuk-inset-text
|
|
868
|
+
# | If you don't fill this in you won't be eligable for a refund
|
|
869
|
+
#
|
|
870
|
+
# @example A date input with legend supplied as a proc
|
|
871
|
+
# = f.govuk_date_field :finishes_on,
|
|
872
|
+
# legend: -> { tag.h3('Which category do you belong to?') }
|
|
873
|
+
def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, &block)
|
|
874
|
+
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
|
|
482
875
|
end
|
|
483
876
|
|
|
484
877
|
# Generates a summary of errors in the form, each linking to the corresponding
|
|
@@ -486,27 +879,27 @@ module GOVUKDesignSystemFormBuilder
|
|
|
486
879
|
#
|
|
487
880
|
# @param title [String] the error summary heading
|
|
488
881
|
#
|
|
489
|
-
# @todo Currently the summary anchors link to the inline error messages themselves rather to
|
|
490
|
-
# the accompanying input. More work is required to improve this and it needs to be
|
|
491
|
-
# handled in a less-generic manner. For example, we can't link to a specific radio button
|
|
492
|
-
# if one hasn't been chosen but we should link to a {#govuk_text_field} if one has been left
|
|
493
|
-
# blank
|
|
494
|
-
#
|
|
495
882
|
# @example An error summary with a custom title
|
|
496
883
|
# = f.govuk_error_summary 'Uh-oh, spaghettios'
|
|
497
884
|
#
|
|
498
885
|
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
|
|
499
|
-
def govuk_error_summary(title =
|
|
886
|
+
def govuk_error_summary(title = config.default_error_summary_title)
|
|
500
887
|
Elements::ErrorSummary.new(self, object_name, title).html
|
|
501
888
|
end
|
|
502
889
|
|
|
503
890
|
# Generates a fieldset containing the contents of the block
|
|
504
891
|
#
|
|
505
|
-
# @param legend [Hash] options for configuring the legend
|
|
892
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
|
506
893
|
# @param described_by [Array<String>] the ids of the elements that describe this fieldset, usually hints and errors
|
|
507
894
|
# @option legend text [String] the fieldset legend's text content
|
|
508
895
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
509
896
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+
|
|
897
|
+
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
|
898
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
|
899
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
900
|
+
# @option caption text [String] the caption text
|
|
901
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
902
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
510
903
|
#
|
|
511
904
|
# @example A fieldset containing address fields
|
|
512
905
|
# = f.govuk_fieldset legend: { text: 'Address' }
|
|
@@ -514,10 +907,16 @@ module GOVUKDesignSystemFormBuilder
|
|
|
514
907
|
# = f.govuk_text_field :town
|
|
515
908
|
# = f.govuk_text_field :city
|
|
516
909
|
#
|
|
910
|
+
# @example A fieldset with the legend as a proc
|
|
911
|
+
# = f.govuk_fieldset legend: -> { tag.h3('Skills') }
|
|
912
|
+
# = f.govuk_text_area :physical
|
|
913
|
+
# = f.govuk_text_area :mental
|
|
914
|
+
#
|
|
517
915
|
# @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
|
|
916
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
518
917
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
519
|
-
def govuk_fieldset(legend: { text: 'Fieldset heading' }, described_by: nil, &block)
|
|
520
|
-
Containers::Fieldset.new(self, legend: legend, described_by: described_by).html
|
|
918
|
+
def govuk_fieldset(legend: { text: 'Fieldset heading' }, caption: {}, described_by: nil, &block)
|
|
919
|
+
Containers::Fieldset.new(self, legend: legend, caption: caption, described_by: described_by, &block).html
|
|
521
920
|
end
|
|
522
921
|
|
|
523
922
|
# Generates an input of type +file+
|
|
@@ -527,21 +926,39 @@ module GOVUKDesignSystemFormBuilder
|
|
|
527
926
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
|
528
927
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
|
529
928
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
530
|
-
# @
|
|
531
|
-
# @
|
|
929
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
930
|
+
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
|
931
|
+
# @option caption text [String] the caption text
|
|
932
|
+
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
933
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
934
|
+
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
|
935
|
+
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
|
936
|
+
# @option hint text [String] the hint text
|
|
937
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
938
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
939
|
+
# @param form_group [Hash] configures the form group
|
|
940
|
+
# @option form_group classes [Array,String] sets the form group's classes
|
|
941
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
532
942
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
533
943
|
#
|
|
534
|
-
# @example A photo upload field with file type specifier
|
|
535
|
-
# = f.govuk_file_field :photo, label: { text: 'Upload your photo' }, accept: 'image/*'
|
|
944
|
+
# @example A photo upload field with file type specifier and injected content
|
|
945
|
+
# = f.govuk_file_field :photo, label: { text: 'Upload your photo' }, accept: 'image/*' do
|
|
946
|
+
#
|
|
947
|
+
# p.govuk-inset-text
|
|
948
|
+
# | Explicit images will result in account termination
|
|
949
|
+
#
|
|
950
|
+
# @example A CV upload field with label as a proc
|
|
951
|
+
# = f.govuk_file_field :cv, label: -> { tag.h3('Upload your CV') }
|
|
536
952
|
#
|
|
537
953
|
# @see https://design-system.service.gov.uk/components/file-upload/ GOV.UK file upload
|
|
954
|
+
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
538
955
|
# @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file MDN documentation for file upload
|
|
539
956
|
#
|
|
540
957
|
# @note Remember to set +multipart: true+ when creating a form with file
|
|
541
958
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
|
542
959
|
# the Rails documentation} for more information
|
|
543
|
-
def govuk_file_field(attribute_name, label: {},
|
|
544
|
-
Elements::File.new(self, object_name, attribute_name, label: label,
|
|
960
|
+
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
|
|
961
|
+
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **kwargs, &block).html
|
|
545
962
|
end
|
|
546
963
|
end
|
|
547
964
|
end
|