govuk_design_system_formbuilder 2.0.0b1 → 2.1.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 +17 -25
- data/lib/govuk_design_system_formbuilder.rb +2 -2
- data/lib/govuk_design_system_formbuilder/builder.rb +127 -74
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +13 -2
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +3 -3
- data/lib/govuk_design_system_formbuilder/elements/caption.rb +10 -5
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +8 -7
- data/lib/govuk_design_system_formbuilder/elements/file.rb +6 -6
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +6 -6
- data/lib/govuk_design_system_formbuilder/elements/label.rb +12 -10
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +25 -11
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +1 -1
- data/lib/govuk_design_system_formbuilder/traits/caption.rb +1 -9
- data/lib/govuk_design_system_formbuilder/traits/input.rb +42 -6
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c55b78722270c864a735be507e018c420e14bee0e408c59da1bc61777c320bf7
|
4
|
+
data.tar.gz: b0d291bca6a13a77fe21db5c431bfea86184de8acd82b5e4cc3a3c944fdf322c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a130e8bb5964af17acb89a14f02ecda2ed989c1e18c6ed970a400945be78c5a8fdc0dd735333b026f51b75a5d090c4e6403f3594feedf595b21c294abec13ae7
|
7
|
+
data.tar.gz: 9afc6f6e12e26bdc2cd4eafc41f2d1e5a972829fd18bd2a2571550b683500320a66f6603d159af0e7c0943b57deeaf8b47267499ac4cf2c3577d207b555cfcba
|
data/README.md
CHANGED
@@ -7,41 +7,32 @@
|
|
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
|
-
This
|
13
|
-
fully-compliant with version 3.8.1 of the [GOV.UK Design System](https://design-system.service.gov.uk/),
|
14
|
-
minimising the amount of markup you need to write.
|
12
|
+
This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
|
15
13
|
|
16
|
-
|
17
|
-
System is exposed via the API. Adding [JavaScript-enhanced word count
|
18
|
-
checking](https://govuk-form-builder.netlify.app/form-elements/text-area/)
|
19
|
-
to text areas or [setting the size and weight of
|
20
|
-
labels](https://govuk-form-builder.netlify.app/introduction/labels-hints-and-legends/)
|
21
|
-
on text fields requires only a single argument.
|
14
|
+
It is intended to make creating forms **quick**, **easy** and **familiar** for Ruby on Rails developers.
|
22
15
|
|
23
16
|
## Documentation 📚
|
24
17
|
|
25
18
|
The gem comes with [a full guide](https://govuk-form-builder.netlify.app/) that
|
26
|
-
covers most aspects of day-to-day use, along with code and output examples. The
|
27
|
-
|
28
|
-
|
29
|
-
If you're still not sure what a form builder is or how it works, don't worry!
|
30
|
-
[This screencast](https://www.youtube.com/watch?v=PhoFZ0qXAlA) should give you
|
31
|
-
an idea of what's on offer and the official guide goes into a bit more depth on
|
32
|
-
how everything works.
|
19
|
+
covers most aspects of day-to-day use, along with code and output examples. The
|
20
|
+
examples in the guide are generated from the builder itself so it will always
|
21
|
+
be up to date.
|
33
22
|
|
34
23
|
[](https://app.netlify.com/sites/govuk-form-builder/deploys)
|
35
24
|
|
36
25
|
## What's included 🧳
|
37
26
|
|
38
27
|
* 100% compatibility with the GOV.UK Design System
|
39
|
-
* Full control of labels, hints,
|
28
|
+
* Full control of labels, legends, hints, captions and fieldsets
|
40
29
|
* No overwriting of Rails' default form helpers
|
41
30
|
* Automatic ARIA associations between hints, errors and inputs
|
42
31
|
* Most helpers take blocks for arbitrary content
|
43
32
|
* Additional params for programmatically adding hints to check box and radio
|
44
33
|
button collections
|
34
|
+
* Full I18n support
|
35
|
+
* Automatic handling of ActiveRecord validation error messages
|
45
36
|
* No external dependencies
|
46
37
|
* An exhaustive test suite
|
47
38
|
* [Extensive technical documentation](https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder)
|
@@ -68,8 +59,9 @@ pre-configured template:
|
|
68
59
|
|
69
60
|
## Setup 🔧
|
70
61
|
|
71
|
-
To use the form builder in an ad hoc basis you can specify it
|
72
|
-
|
62
|
+
To use the form builder in an ad hoc basis you can specify it as an argument to
|
63
|
+
`form_for` or `form_with`. These examples are written in [Slim](https://slim-lang.com) but
|
64
|
+
other templating languages like ERB and [Haml](https://haml.info/) work just as well.
|
73
65
|
|
74
66
|
```slim
|
75
67
|
= form_for @some_object, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f|
|
@@ -99,16 +91,16 @@ Now we can get started!
|
|
99
91
|
:name,
|
100
92
|
:description,
|
101
93
|
label: { text: "Which department do you work for?" },
|
102
|
-
|
94
|
+
hint: { text: "If you don't know ask your manager" }
|
103
95
|
|
104
96
|
= f.govuk_submit 'Away we go!'
|
105
97
|
```
|
106
98
|
|
107
99
|
## Developing and running the tests 👨🏻🏭
|
108
100
|
|
109
|
-
The form builder is
|
110
|
-
|
111
|
-
|
101
|
+
The form builder is tested with RSpec. To run all the tests first ensure that
|
102
|
+
the development and testing prerequisite gems are installed. At the root of a
|
103
|
+
freshly-cloned repo run:
|
112
104
|
|
113
105
|
```sh
|
114
106
|
bundle
|
@@ -117,7 +109,7 @@ bundle
|
|
117
109
|
Now, if everything was successful, run RSpec:
|
118
110
|
|
119
111
|
```sh
|
120
|
-
bundle exec rspec
|
112
|
+
bundle exec rspec
|
121
113
|
```
|
122
114
|
|
123
115
|
## Contributing 📦
|
@@ -21,7 +21,7 @@ module GOVUKDesignSystemFormBuilder
|
|
21
21
|
# Can be either +xl+, +l+, +m+ or +s+.
|
22
22
|
#
|
23
23
|
# * +:default_legend_tag+ controls the default tag that legends are
|
24
|
-
# wrapped in. Defaults to +
|
24
|
+
# wrapped in. Defaults to +nil+.
|
25
25
|
#
|
26
26
|
# * +:default_submit_button_text+ sets the value assigned to +govuk_submit+,
|
27
27
|
# defaults to 'Continue'.
|
@@ -47,7 +47,7 @@ module GOVUKDesignSystemFormBuilder
|
|
47
47
|
brand: 'govuk',
|
48
48
|
|
49
49
|
default_legend_size: 'm',
|
50
|
-
default_legend_tag:
|
50
|
+
default_legend_tag: nil,
|
51
51
|
default_caption_size: 'm',
|
52
52
|
default_submit_button_text: 'Continue',
|
53
53
|
default_radio_divider_text: 'or',
|
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
|
|
8
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
9
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
10
10
|
# @option hint text [String] the hint text
|
11
|
-
# @option hint
|
11
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
12
12
|
#
|
13
13
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
14
14
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
@@ -17,13 +17,17 @@ module GOVUKDesignSystemFormBuilder
|
|
17
17
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
18
18
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
19
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
|
20
21
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
21
22
|
# @option caption text [String] the caption text
|
22
23
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
23
|
-
# @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
|
24
26
|
# @param form_group [Hash] configures the form group
|
25
27
|
# @option form_group classes [Array,String] sets the form group's classes
|
26
|
-
# @option form_group
|
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+
|
27
31
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
28
32
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
29
33
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -47,8 +51,8 @@ module GOVUKDesignSystemFormBuilder
|
|
47
51
|
# = f.govuk_text_field :callsign,
|
48
52
|
# label: -> { tag.h3('Call-sign') }
|
49
53
|
#
|
50
|
-
def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
51
|
-
Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
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
|
52
56
|
end
|
53
57
|
|
54
58
|
# Generates a input of type +tel+
|
@@ -57,7 +61,7 @@ module GOVUKDesignSystemFormBuilder
|
|
57
61
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
58
62
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
59
63
|
# @option hint text [String] the hint text
|
60
|
-
# @option hint
|
64
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
61
65
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
62
66
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
63
67
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -65,13 +69,17 @@ module GOVUKDesignSystemFormBuilder
|
|
65
69
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
66
70
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
67
71
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
72
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
68
73
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
69
74
|
# @option caption text [String] the caption text
|
70
75
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
71
|
-
# @option
|
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
|
72
78
|
# @param form_group [Hash] configures the form group
|
73
79
|
# @option form_group classes [Array,String] sets the form group's classes
|
74
|
-
# @option form_group
|
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+
|
75
83
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
76
84
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
77
85
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -96,8 +104,8 @@ module GOVUKDesignSystemFormBuilder
|
|
96
104
|
# = f.govuk_phone_field :work_number,
|
97
105
|
# label: -> { tag.h3('Work number') }
|
98
106
|
#
|
99
|
-
def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
100
|
-
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
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
|
101
109
|
end
|
102
110
|
|
103
111
|
# Generates a input of type +email+
|
@@ -106,7 +114,7 @@ module GOVUKDesignSystemFormBuilder
|
|
106
114
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
107
115
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
108
116
|
# @option hint text [String] the hint text
|
109
|
-
# @option hint
|
117
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
110
118
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
111
119
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
112
120
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -114,13 +122,17 @@ module GOVUKDesignSystemFormBuilder
|
|
114
122
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
115
123
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
116
124
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
125
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
117
126
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
118
127
|
# @option caption text [String] the caption text
|
119
128
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
120
|
-
# @option
|
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
|
121
131
|
# @param form_group [Hash] configures the form group
|
122
132
|
# @option form_group classes [Array,String] sets the form group's classes
|
123
|
-
# @option form_group
|
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+
|
124
136
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
125
137
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
126
138
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -143,8 +155,8 @@ module GOVUKDesignSystemFormBuilder
|
|
143
155
|
# = f.govuk_email_field :personal_email,
|
144
156
|
# label: -> { tag.h3('Personal email address') }
|
145
157
|
#
|
146
|
-
def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
147
|
-
Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
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
|
148
160
|
end
|
149
161
|
|
150
162
|
# Generates a input of type +password+
|
@@ -153,7 +165,7 @@ module GOVUKDesignSystemFormBuilder
|
|
153
165
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
154
166
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
155
167
|
# @option hint text [String] the hint text
|
156
|
-
# @option hint
|
168
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
157
169
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
158
170
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
159
171
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -161,13 +173,17 @@ module GOVUKDesignSystemFormBuilder
|
|
161
173
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
162
174
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
163
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
|
164
177
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
165
178
|
# @option caption text [String] the caption text
|
166
179
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
167
|
-
# @option
|
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
|
168
182
|
# @param form_group [Hash] configures the form group
|
169
183
|
# @option form_group classes [Array,String] sets the form group's classes
|
170
|
-
# @option form_group
|
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+
|
171
187
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
172
188
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
173
189
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -189,8 +205,8 @@ module GOVUKDesignSystemFormBuilder
|
|
189
205
|
# = f.govuk_password_field :passcode,
|
190
206
|
# label: -> { tag.h3('What is your secret pass code?') }
|
191
207
|
#
|
192
|
-
def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, form_group: {}, caption: {}, **
|
193
|
-
Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
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
|
194
210
|
end
|
195
211
|
|
196
212
|
# Generates a input of type +url+
|
@@ -199,7 +215,7 @@ module GOVUKDesignSystemFormBuilder
|
|
199
215
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
200
216
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
201
217
|
# @option hint text [String] the hint text
|
202
|
-
# @option hint
|
218
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
203
219
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
204
220
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
205
221
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -207,13 +223,17 @@ module GOVUKDesignSystemFormBuilder
|
|
207
223
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
208
224
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
209
225
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
226
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
210
227
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
211
228
|
# @option caption text [String] the caption text
|
212
229
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
213
|
-
# @option
|
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
|
214
232
|
# @param form_group [Hash] configures the form group
|
215
233
|
# @option form_group classes [Array,String] sets the form group's classes
|
216
|
-
# @option form_group
|
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+
|
217
237
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
218
238
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
219
239
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -236,8 +256,8 @@ module GOVUKDesignSystemFormBuilder
|
|
236
256
|
# = f.govuk_url_field :work_website,
|
237
257
|
# label: -> { tag.h3("Enter your company's website") }
|
238
258
|
#
|
239
|
-
def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
240
|
-
Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
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
|
241
261
|
end
|
242
262
|
|
243
263
|
# Generates a input of type +number+
|
@@ -246,7 +266,7 @@ module GOVUKDesignSystemFormBuilder
|
|
246
266
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
247
267
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
248
268
|
# @option hint text [String] the hint text
|
249
|
-
# @option hint
|
269
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
250
270
|
# @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
|
251
271
|
# or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
|
252
272
|
# @param label [Hash,Proc] configures or sets the associated label content
|
@@ -254,13 +274,17 @@ module GOVUKDesignSystemFormBuilder
|
|
254
274
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
255
275
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
256
276
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
277
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
257
278
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
258
279
|
# @option caption text [String] the caption text
|
259
280
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
260
|
-
# @option
|
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
|
261
283
|
# @param form_group [Hash] configures the form group
|
262
284
|
# @option form_group classes [Array,String] sets the form group's classes
|
263
|
-
# @option form_group
|
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+
|
264
288
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
265
289
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
266
290
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -286,8 +310,8 @@ module GOVUKDesignSystemFormBuilder
|
|
286
310
|
# = f.govuk_url_field :personal_best_over_100m,
|
287
311
|
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
|
288
312
|
#
|
289
|
-
def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **
|
290
|
-
Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **
|
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
|
291
315
|
end
|
292
316
|
|
293
317
|
# Generates a +textarea+ element with a label, optional hint. Also offers
|
@@ -298,23 +322,25 @@ module GOVUKDesignSystemFormBuilder
|
|
298
322
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
299
323
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
300
324
|
# @option hint text [String] the hint text
|
301
|
-
# @option hint
|
325
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
302
326
|
# @param label [Hash,Proc] configures or sets the associated label content
|
303
327
|
# @option label text [String] the label text
|
304
328
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
305
329
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
306
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
|
307
332
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
308
333
|
# @option caption text [String] the caption text
|
309
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
|
310
336
|
# @param max_words [Integer] adds the GOV.UK max word count
|
311
337
|
# @param max_chars [Integer] adds the GOV.UK max characters count
|
312
338
|
# @param threshold [Integer] only show the +max_words+ and +max_chars+ warnings once a threshold (percentage) is reached
|
313
339
|
# @param rows [Integer] sets the initial number of rows
|
314
|
-
# @option
|
340
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +textarea+ element
|
315
341
|
# @param form_group [Hash] configures the form group
|
316
342
|
# @option form_group classes [Array,String] sets the form group's classes
|
317
|
-
# @option form_group
|
343
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
318
344
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
319
345
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
320
346
|
# @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
|
@@ -340,8 +366,8 @@ module GOVUKDesignSystemFormBuilder
|
|
340
366
|
# = f.govuk_text_area :instructions,
|
341
367
|
# label: -> { tag.h3("How do you set it up?") }
|
342
368
|
#
|
343
|
-
def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **
|
344
|
-
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, **
|
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
|
345
371
|
end
|
346
372
|
|
347
373
|
# Generates a +select+ element containing +option+ for each member in the provided collection
|
@@ -353,16 +379,17 @@ module GOVUKDesignSystemFormBuilder
|
|
353
379
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
354
380
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
355
381
|
# @option hint text [String] the hint text
|
356
|
-
# @option hint
|
382
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
357
383
|
# @option label text [String] the label text
|
358
384
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
359
385
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
360
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
|
361
388
|
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
362
389
|
# @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
|
363
390
|
# @param form_group [Hash] configures the form group
|
364
391
|
# @option form_group classes [Array,String] sets the form group's classes
|
365
|
-
# @option form_group
|
392
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
366
393
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
367
394
|
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
368
395
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -424,19 +451,21 @@ module GOVUKDesignSystemFormBuilder
|
|
424
451
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
425
452
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
426
453
|
# @option hint text [String] the hint text
|
427
|
-
# @option hint
|
428
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
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+.
|
429
456
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
430
457
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
431
458
|
# @param bold_labels [Boolean] controls whether the radio button labels are bold
|
432
459
|
# @param classes [Array,String] Classes to add to the radio button container.
|
433
460
|
# @option legend text [String] the fieldset legend's text content
|
434
461
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
435
|
-
# @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+.
|
436
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
|
437
465
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
438
466
|
# @option caption text [String] the caption text
|
439
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
|
440
469
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
441
470
|
#
|
442
471
|
# @example A collection of radio buttons for favourite colours, labels capitalised via a proc
|
@@ -471,7 +500,7 @@ module GOVUKDesignSystemFormBuilder
|
|
471
500
|
# :name,
|
472
501
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
473
502
|
#
|
474
|
-
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)
|
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)
|
475
504
|
Elements::Radios::Collection.new(
|
476
505
|
self,
|
477
506
|
object_name,
|
@@ -503,20 +532,22 @@ module GOVUKDesignSystemFormBuilder
|
|
503
532
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
504
533
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
505
534
|
# @option hint text [String] the hint text
|
506
|
-
# @option hint
|
507
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
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+.
|
508
537
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
509
538
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
510
539
|
# @option legend text [String] the fieldset legend's text content
|
511
540
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
512
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
541
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
513
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
|
514
544
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
515
545
|
# @option caption text [String] the caption text
|
516
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
|
517
548
|
# @param form_group [Hash] configures the form group
|
518
549
|
# @option form_group classes [Array,String] sets the form group's classes
|
519
|
-
# @option form_group
|
550
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
520
551
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
521
552
|
# @param classes [Array,String] Classes to add to the radio button container.
|
522
553
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
@@ -551,11 +582,13 @@ module GOVUKDesignSystemFormBuilder
|
|
551
582
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
552
583
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
553
584
|
# @option hint text [String] the hint text
|
554
|
-
# @option hint
|
555
|
-
# @
|
556
|
-
# @option
|
557
|
-
# @option
|
558
|
-
# @option
|
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
|
559
592
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
560
593
|
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
561
594
|
# @param block [Block] Any supplied HTML will be wrapped in a conditional
|
@@ -596,20 +629,21 @@ module GOVUKDesignSystemFormBuilder
|
|
596
629
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
597
630
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
598
631
|
# @option hint text [String] the hint text
|
599
|
-
# @option hint
|
632
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
600
633
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
601
634
|
# @param classes [Array,String] Classes to add to the checkbox container.
|
602
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
635
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
603
636
|
# @option legend text [String] the fieldset legend's text content
|
604
637
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
605
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
638
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
606
639
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
607
640
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
608
641
|
# @option caption text [String] the caption text
|
609
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
|
610
644
|
# @param form_group [Hash] configures the form group
|
611
645
|
# @option form_group classes [Array,String] sets the form group's classes
|
612
|
-
# @option form_group
|
646
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
613
647
|
# @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
|
614
648
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
615
649
|
#
|
@@ -674,20 +708,24 @@ module GOVUKDesignSystemFormBuilder
|
|
674
708
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
675
709
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
676
710
|
# @option hint text [String] the hint text
|
677
|
-
# @option hint
|
711
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
678
712
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
679
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
713
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
680
714
|
# @option legend text [String] the fieldset legend's text content
|
681
715
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
682
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
716
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
683
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
|
684
719
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
685
720
|
# @option caption text [String] the caption text
|
686
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
|
687
723
|
# @param classes [Array,String] Classes to add to the checkbox container.
|
688
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>)
|
689
727
|
# @option form_group classes [Array,String] sets the form group's classes
|
690
|
-
# @option form_group
|
728
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
691
729
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
692
730
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
693
731
|
#
|
@@ -701,7 +739,7 @@ module GOVUKDesignSystemFormBuilder
|
|
701
739
|
# = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
|
702
740
|
# = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
|
703
741
|
#
|
704
|
-
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, classes: nil, form_group: {}, &block)
|
742
|
+
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, classes: nil, form_group: {}, multiple: true, &block)
|
705
743
|
Containers::CheckBoxesFieldset.new(
|
706
744
|
self,
|
707
745
|
object_name,
|
@@ -712,6 +750,7 @@ module GOVUKDesignSystemFormBuilder
|
|
712
750
|
small: small,
|
713
751
|
classes: classes,
|
714
752
|
form_group: form_group,
|
753
|
+
multiple: multiple,
|
715
754
|
&block
|
716
755
|
).html
|
717
756
|
end
|
@@ -720,15 +759,17 @@ module GOVUKDesignSystemFormBuilder
|
|
720
759
|
#
|
721
760
|
# @param attribute_name [Symbol] The name of the attribute
|
722
761
|
# @param value [Boolean,String,Symbol,Integer] The value of the checkbox when it is checked
|
762
|
+
# @param unchecked_value [Boolean,String,Symbol,Integer] The value of the checkbox when it is unchecked
|
723
763
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
724
764
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
725
765
|
# @option hint text [String] the hint text
|
726
|
-
# @option hint
|
766
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
727
767
|
# @param link_errors [Boolean] controls whether this radio button should be linked to from {#govuk_error_summary}
|
728
768
|
# @option label text [String] the label text
|
729
769
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
730
770
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
731
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
|
732
773
|
# @param multiple [Boolean] controls whether the check box is part of a collection or represents a single attribute
|
733
774
|
# @param block [Block] any HTML passed in will form the contents of the fieldset
|
734
775
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
@@ -741,12 +782,13 @@ module GOVUKDesignSystemFormBuilder
|
|
741
782
|
# label: { text: 'Do you agree with our terms and conditions?' },
|
742
783
|
# hint: { text: 'You will not be able to proceed unless you do' }
|
743
784
|
#
|
744
|
-
def govuk_check_box(attribute_name, value, hint: {}, label: {}, link_errors: false, multiple: true, &block)
|
785
|
+
def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, &block)
|
745
786
|
Elements::CheckBoxes::FieldsetCheckBox.new(
|
746
787
|
self,
|
747
788
|
object_name,
|
748
789
|
attribute_name,
|
749
790
|
value,
|
791
|
+
unchecked_value,
|
750
792
|
hint: hint,
|
751
793
|
label: label,
|
752
794
|
link_errors: link_errors,
|
@@ -774,6 +816,8 @@ module GOVUKDesignSystemFormBuilder
|
|
774
816
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
775
817
|
# @note Only the first additional button or link (passed in via a block) will be given the
|
776
818
|
# correct left margin, subsequent buttons will need to be manually accounted for
|
819
|
+
# @note This helper always renders an +<input type='submit'>+ tag, HTML content is not supported inside. You
|
820
|
+
# can place +<button>+ tags inside the form to have the same effect
|
777
821
|
# @see https://design-system.service.gov.uk/components/button/#stop-users-from-accidentally-sending-information-more-than-once
|
778
822
|
# GOV.UK double click prevention
|
779
823
|
#
|
@@ -794,19 +838,21 @@ module GOVUKDesignSystemFormBuilder
|
|
794
838
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
795
839
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
796
840
|
# @option hint text [String] the hint text
|
797
|
-
# @option hint
|
798
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
841
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
842
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
799
843
|
# @option legend text [String] the fieldset legend's text content
|
800
844
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
801
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
845
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
802
846
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
847
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
803
848
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
804
849
|
# @option caption text [String] the caption text
|
805
850
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
851
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
806
852
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
807
853
|
# @param form_group [Hash] configures the form group
|
808
854
|
# @option form_group classes [Array,String] sets the form group's classes
|
809
|
-
# @option form_group
|
855
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
810
856
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
811
857
|
# @param date_of_birth [Boolean] if +true+ {https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Values birth date auto completion attributes}
|
812
858
|
# will be added to the inputs
|
@@ -835,6 +881,9 @@ module GOVUKDesignSystemFormBuilder
|
|
835
881
|
#
|
836
882
|
# @param title [String] the error summary heading
|
837
883
|
#
|
884
|
+
# @note Only the first error in the +#errors+ array for each attribute will
|
885
|
+
# be included.
|
886
|
+
#
|
838
887
|
# @example An error summary with a custom title
|
839
888
|
# = f.govuk_error_summary 'Uh-oh, spaghettios'
|
840
889
|
#
|
@@ -845,24 +894,26 @@ module GOVUKDesignSystemFormBuilder
|
|
845
894
|
|
846
895
|
# Generates a fieldset containing the contents of the block
|
847
896
|
#
|
848
|
-
# @param legend [Hash,Proc] options for configuring the legend
|
897
|
+
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
849
898
|
# @param described_by [Array<String>] the ids of the elements that describe this fieldset, usually hints and errors
|
850
899
|
# @option legend text [String] the fieldset legend's text content
|
851
900
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
852
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
901
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
853
902
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
903
|
+
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
854
904
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
855
905
|
# @option caption text [String] the caption text
|
856
906
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
907
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
857
908
|
#
|
858
909
|
# @example A fieldset containing address fields
|
859
|
-
# = f.govuk_fieldset legend: { text: 'Address' }
|
910
|
+
# = f.govuk_fieldset legend: { text: 'Address' } do
|
860
911
|
# = f.govuk_text_field :street
|
861
912
|
# = f.govuk_text_field :town
|
862
913
|
# = f.govuk_text_field :city
|
863
914
|
#
|
864
915
|
# @example A fieldset with the legend as a proc
|
865
|
-
# = f.govuk_fieldset legend: -> { tag.h3('Skills') }
|
916
|
+
# = f.govuk_fieldset legend: -> { tag.h3('Skills') } do
|
866
917
|
# = f.govuk_text_area :physical
|
867
918
|
# = f.govuk_text_area :mental
|
868
919
|
#
|
@@ -880,17 +931,19 @@ module GOVUKDesignSystemFormBuilder
|
|
880
931
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
881
932
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
882
933
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
934
|
+
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
883
935
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
884
936
|
# @option caption text [String] the caption text
|
885
937
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
938
|
+
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
886
939
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
887
940
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
888
941
|
# @option hint text [String] the hint text
|
889
|
-
# @option hint
|
890
|
-
# @option
|
942
|
+
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
943
|
+
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
891
944
|
# @param form_group [Hash] configures the form group
|
892
945
|
# @option form_group classes [Array,String] sets the form group's classes
|
893
|
-
# @option form_group
|
946
|
+
# @option form_group kwargs [Hash] additional attributes added to the form group
|
894
947
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
895
948
|
#
|
896
949
|
# @example A photo upload field with file type specifier and injected content
|
@@ -909,8 +962,8 @@ module GOVUKDesignSystemFormBuilder
|
|
909
962
|
# @note Remember to set +multipart: true+ when creating a form with file
|
910
963
|
# uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
|
911
964
|
# the Rails documentation} for more information
|
912
|
-
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **
|
913
|
-
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **
|
965
|
+
def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, **kwargs, &block)
|
966
|
+
Elements::File.new(self, object_name, attribute_name, label: label, caption: caption, hint: hint, form_group: form_group, **kwargs, &block).html
|
914
967
|
end
|
915
968
|
end
|
916
969
|
end
|
@@ -4,7 +4,7 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
include Traits::Error
|
5
5
|
include Traits::Hint
|
6
6
|
|
7
|
-
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, small:, classes:, form_group:, &block)
|
7
|
+
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, small:, classes:, form_group:, multiple:, &block)
|
8
8
|
super(builder, object_name, attribute_name, &block)
|
9
9
|
|
10
10
|
@legend = legend
|
@@ -13,19 +13,30 @@ module GOVUKDesignSystemFormBuilder
|
|
13
13
|
@small = small
|
14
14
|
@classes = classes
|
15
15
|
@form_group = form_group
|
16
|
+
@multiple = multiple
|
16
17
|
@block_content = capture { block.call }
|
17
18
|
end
|
18
19
|
|
19
20
|
def html
|
20
21
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
21
22
|
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
22
|
-
safe_join([hint_element, error_element, checkboxes])
|
23
|
+
safe_join([hint_element, error_element, hidden_field, checkboxes])
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
30
|
+
def hidden_field
|
31
|
+
return unless @multiple
|
32
|
+
|
33
|
+
@builder.hidden_field(@attribute_name, value: "", name: hidden_field_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def hidden_field_name
|
37
|
+
format("%<object_name>s[%<attribute_name>s][]", object_name: @object_name, attribute_name: @attribute_name)
|
38
|
+
end
|
39
|
+
|
29
40
|
def fieldset_options
|
30
41
|
{
|
31
42
|
legend: @legend,
|
@@ -4,12 +4,12 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
def initialize(builder, object_name, attribute_name, classes: nil, **kwargs)
|
5
5
|
super(builder, object_name, attribute_name)
|
6
6
|
|
7
|
-
@classes
|
8
|
-
@
|
7
|
+
@classes = classes
|
8
|
+
@html_attributes = kwargs
|
9
9
|
end
|
10
10
|
|
11
11
|
def html
|
12
|
-
tag.div(class: classes, **@
|
12
|
+
tag.div(class: classes, **@html_attributes) { yield }
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -3,21 +3,26 @@ module GOVUKDesignSystemFormBuilder
|
|
3
3
|
class Caption < Base
|
4
4
|
include Traits::Localisation
|
5
5
|
|
6
|
-
def initialize(builder, object_name, attribute_name, text
|
6
|
+
def initialize(builder, object_name, attribute_name, text: nil, size: nil, **kwargs)
|
7
7
|
super(builder, object_name, attribute_name)
|
8
8
|
|
9
|
-
@text
|
10
|
-
@size_class
|
9
|
+
@text = text(text)
|
10
|
+
@size_class = size_class(size)
|
11
|
+
@html_attributes = kwargs
|
11
12
|
end
|
12
13
|
|
13
14
|
def html
|
14
|
-
return nil
|
15
|
+
return nil unless active?
|
15
16
|
|
16
|
-
tag.span(@text, class: @size_class)
|
17
|
+
tag.span(@text, class: @size_class, **@html_attributes)
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
20
21
|
|
22
|
+
def active?
|
23
|
+
@text.present?
|
24
|
+
end
|
25
|
+
|
21
26
|
def text(override)
|
22
27
|
override || localised_text(:caption)
|
23
28
|
end
|
@@ -8,14 +8,15 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
include Traits::Hint
|
9
9
|
include Traits::Conditional
|
10
10
|
|
11
|
-
def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, multiple:, &block)
|
11
|
+
def initialize(builder, object_name, attribute_name, value, unchecked_value, label:, hint:, link_errors:, multiple:, &block)
|
12
12
|
super(builder, object_name, attribute_name)
|
13
13
|
|
14
|
-
@value
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
14
|
+
@value = value
|
15
|
+
@unchecked_value = unchecked_value
|
16
|
+
@label = label
|
17
|
+
@hint = hint
|
18
|
+
@multiple = multiple
|
19
|
+
@link_errors = link_errors
|
19
20
|
|
20
21
|
if block_given?
|
21
22
|
@conditional_content = wrap_conditional(block)
|
@@ -36,7 +37,7 @@ module GOVUKDesignSystemFormBuilder
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def check_box
|
39
|
-
@builder.check_box(@attribute_name, options, @value,
|
40
|
+
@builder.check_box(@attribute_name, options, @value, @unchecked_value)
|
40
41
|
end
|
41
42
|
|
42
43
|
def options
|
@@ -11,11 +11,11 @@ module GOVUKDesignSystemFormBuilder
|
|
11
11
|
def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
|
12
12
|
super(builder, object_name, attribute_name, &block)
|
13
13
|
|
14
|
-
@label
|
15
|
-
@caption
|
16
|
-
@hint
|
17
|
-
@
|
18
|
-
@form_group
|
14
|
+
@label = label
|
15
|
+
@caption = caption
|
16
|
+
@hint = hint
|
17
|
+
@html_attributes = kwargs
|
18
|
+
@form_group = form_group
|
19
19
|
end
|
20
20
|
|
21
21
|
def html
|
@@ -27,7 +27,7 @@ module GOVUKDesignSystemFormBuilder
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def file
|
30
|
-
@builder.file_field(@attribute_name, **options, **@
|
30
|
+
@builder.file_field(@attribute_name, **options, **@html_attributes)
|
31
31
|
end
|
32
32
|
|
33
33
|
def options
|
@@ -8,20 +8,20 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
def initialize(builder, object_name, attribute_name, value: nil, text: nil, content: nil, radio: false, checkbox: false, **kwargs)
|
9
9
|
super(builder, object_name, attribute_name)
|
10
10
|
|
11
|
+
@value = value
|
11
12
|
@radio = radio
|
12
13
|
@checkbox = checkbox
|
13
14
|
@html_attributes = kwargs
|
14
15
|
|
15
16
|
if content
|
16
|
-
@
|
17
|
+
@raw = capture { content.call }
|
17
18
|
else
|
18
|
-
@text
|
19
|
-
@value = value
|
19
|
+
@text = retrieve_text(text)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def active?
|
24
|
-
[@text, @
|
24
|
+
[@text, @raw].any?(&:present?)
|
25
25
|
end
|
26
26
|
|
27
27
|
def html
|
@@ -43,11 +43,11 @@ module GOVUKDesignSystemFormBuilder
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def hint_tag
|
46
|
-
@
|
46
|
+
@raw.presence ? 'div' : 'span'
|
47
47
|
end
|
48
48
|
|
49
49
|
def hint_body
|
50
|
-
@
|
50
|
+
@raw || @text
|
51
51
|
end
|
52
52
|
|
53
53
|
def retrieve_text(supplied)
|
@@ -6,22 +6,24 @@ module GOVUKDesignSystemFormBuilder
|
|
6
6
|
include Traits::Caption
|
7
7
|
include Traits::Localisation
|
8
8
|
|
9
|
-
def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true, content: nil, caption: nil)
|
9
|
+
def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true, content: nil, caption: nil, **kwargs)
|
10
10
|
super(builder, object_name, attribute_name)
|
11
11
|
|
12
|
+
@value = value # used by field_id
|
13
|
+
@tag = tag
|
14
|
+
@radio = radio
|
15
|
+
@checkbox = checkbox
|
16
|
+
@link_errors = link_errors
|
17
|
+
@html_attributes = kwargs
|
18
|
+
|
12
19
|
# content is passed in directly via a proc and overrides
|
13
20
|
# the other display options
|
14
21
|
if content
|
15
22
|
@content = capture { content.call }
|
16
23
|
else
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@radio = radio
|
21
|
-
@checkbox = checkbox
|
22
|
-
@tag = tag
|
23
|
-
@link_errors = link_errors
|
24
|
-
@caption = caption
|
24
|
+
@text = retrieve_text(text, hidden)
|
25
|
+
@size_class = size_class(size)
|
26
|
+
@caption = caption
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -42,7 +44,7 @@ module GOVUKDesignSystemFormBuilder
|
|
42
44
|
private
|
43
45
|
|
44
46
|
def label
|
45
|
-
@builder.label(@attribute_name, **options) do
|
47
|
+
@builder.label(@attribute_name, **options, **@html_attributes) do
|
46
48
|
@content || safe_join([caption, @text])
|
47
49
|
end
|
48
50
|
end
|
@@ -4,22 +4,26 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
include Traits::Caption
|
5
5
|
include Traits::Localisation
|
6
6
|
|
7
|
-
def initialize(builder, object_name, attribute_name, legend:, caption
|
7
|
+
def initialize(builder, object_name, attribute_name, legend:, caption:, **kwargs)
|
8
8
|
super(builder, object_name, attribute_name)
|
9
9
|
|
10
|
+
@html_attributes = kwargs
|
11
|
+
|
10
12
|
case legend
|
13
|
+
when NilClass
|
14
|
+
# do nothing
|
11
15
|
when Proc
|
12
16
|
@raw = capture { legend.call }
|
13
17
|
when Hash
|
14
18
|
defaults.merge(legend).tap do |l|
|
15
|
-
@text =
|
19
|
+
@text = retrieve_text(l.dig(:text))
|
16
20
|
@hidden = l.dig(:hidden)
|
17
21
|
@tag = l.dig(:tag)
|
18
22
|
@size = l.dig(:size)
|
19
23
|
@caption = caption
|
20
24
|
end
|
21
25
|
else
|
22
|
-
fail(ArgumentError, %(legend must be a Proc or Hash))
|
26
|
+
fail(ArgumentError, %(legend must be a NilClass, Proc or Hash))
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -29,18 +33,28 @@ module GOVUKDesignSystemFormBuilder
|
|
29
33
|
|
30
34
|
private
|
31
35
|
|
36
|
+
def active?
|
37
|
+
[@text, @raw].any?(&:present?)
|
38
|
+
end
|
39
|
+
|
32
40
|
def content
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
return unless active?
|
42
|
+
|
43
|
+
tag.legend(legend_text, class: classes, **@html_attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
def legend_text
|
47
|
+
caption_and_text = safe_join([caption_element, @text])
|
48
|
+
|
49
|
+
if @tag.present?
|
50
|
+
content_tag(@tag, class: heading_classes) { caption_and_text }
|
51
|
+
else
|
52
|
+
caption_and_text
|
39
53
|
end
|
40
54
|
end
|
41
55
|
|
42
|
-
def
|
43
|
-
supplied_text
|
56
|
+
def retrieve_text(supplied_text)
|
57
|
+
[supplied_text, localised_text(:legend), @attribute_name&.capitalize].compact.first
|
44
58
|
end
|
45
59
|
|
46
60
|
def classes
|
@@ -39,7 +39,7 @@ module GOVUKDesignSystemFormBuilder
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def label_element
|
42
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options
|
42
|
+
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
|
43
43
|
end
|
44
44
|
|
45
45
|
def label_options
|
@@ -8,15 +8,7 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def caption_options
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def caption_text
|
15
|
-
@caption&.dig(:text)
|
16
|
-
end
|
17
|
-
|
18
|
-
def caption_size
|
19
|
-
@caption&.dig(:size)
|
11
|
+
@caption
|
20
12
|
end
|
21
13
|
end
|
22
14
|
end
|
@@ -1,38 +1,58 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Traits
|
3
3
|
module Input
|
4
|
-
def initialize(builder, object_name, attribute_name, hint:, label:, caption:, width:, form_group:, **kwargs, &block)
|
4
|
+
def initialize(builder, object_name, attribute_name, hint:, label:, caption:, prefix_text:, suffix_text:, width:, form_group:, **kwargs, &block)
|
5
5
|
super(builder, object_name, attribute_name, &block)
|
6
6
|
|
7
7
|
@width = width
|
8
8
|
@label = label
|
9
9
|
@caption = caption
|
10
10
|
@hint = hint
|
11
|
+
@prefix_text = prefix_text
|
12
|
+
@suffix_text = suffix_text
|
11
13
|
@html_attributes = kwargs
|
12
14
|
@form_group = form_group
|
13
15
|
end
|
14
16
|
|
15
17
|
def html
|
16
18
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
17
|
-
safe_join([label_element, supplemental_content, hint_element, error_element,
|
19
|
+
safe_join([label_element, supplemental_content, hint_element, error_element, content])
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
22
24
|
|
25
|
+
def content
|
26
|
+
if affixed?
|
27
|
+
affixed_input
|
28
|
+
else
|
29
|
+
input
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def affixed_input
|
34
|
+
content_tag('div', class: %(#{brand}-input__wrapper)) do
|
35
|
+
safe_join([prefix, input, suffix])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
23
39
|
def input
|
24
|
-
@builder.send(builder_method, @attribute_name, **
|
40
|
+
@builder.send(builder_method, @attribute_name, **options, **@html_attributes)
|
41
|
+
end
|
42
|
+
|
43
|
+
def affixed?
|
44
|
+
[@prefix_text, @suffix_text].any?
|
25
45
|
end
|
26
46
|
|
27
|
-
def
|
47
|
+
def options
|
28
48
|
{
|
29
49
|
id: field_id(link_errors: true),
|
30
|
-
class:
|
50
|
+
class: classes,
|
31
51
|
aria: { describedby: described_by(hint_id, error_id, supplemental_id) }
|
32
52
|
}
|
33
53
|
end
|
34
54
|
|
35
|
-
def
|
55
|
+
def classes
|
36
56
|
[%(#{brand}-input)].push(width_classes, error_classes).compact
|
37
57
|
end
|
38
58
|
|
@@ -64,6 +84,22 @@ module GOVUKDesignSystemFormBuilder
|
|
64
84
|
else fail(ArgumentError, "invalid width '#{@width}'")
|
65
85
|
end
|
66
86
|
end
|
87
|
+
|
88
|
+
def prefix
|
89
|
+
return nil if @prefix_text.blank?
|
90
|
+
|
91
|
+
tag.span(@prefix_text, class: %(#{brand}-input__prefix), **affix_options)
|
92
|
+
end
|
93
|
+
|
94
|
+
def suffix
|
95
|
+
return nil if @suffix_text.blank?
|
96
|
+
|
97
|
+
tag.span(@suffix_text, class: %(#{brand}-input__suffix), **affix_options)
|
98
|
+
end
|
99
|
+
|
100
|
+
def affix_options
|
101
|
+
{ aria: { hidden: true } }
|
102
|
+
end
|
67
103
|
end
|
68
104
|
end
|
69
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_design_system_formbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Yates
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -134,14 +134,14 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: 0.
|
137
|
+
version: 0.17.1
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: 0.
|
144
|
+
version: 0.17.1
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: htmlbeautifier
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,14 +176,14 @@ dependencies:
|
|
176
176
|
requirements:
|
177
177
|
- - "~>"
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version: 3.
|
179
|
+
version: 3.23.0
|
180
180
|
type: :development
|
181
181
|
prerelease: false
|
182
182
|
version_requirements: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
184
|
- - "~>"
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version: 3.
|
186
|
+
version: 3.23.0
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: rubypants
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -303,7 +303,7 @@ metadata:
|
|
303
303
|
documentation_uri: https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder
|
304
304
|
homepage_uri: https://govuk-form-builder.netlify.app
|
305
305
|
source_code_uri: https://github.com/DFE-Digital/govuk_design_system_formbuilder
|
306
|
-
post_install_message:
|
306
|
+
post_install_message:
|
307
307
|
rdoc_options: []
|
308
308
|
require_paths:
|
309
309
|
- lib
|
@@ -314,12 +314,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
314
314
|
version: '0'
|
315
315
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
316
316
|
requirements:
|
317
|
-
- - "
|
317
|
+
- - ">="
|
318
318
|
- !ruby/object:Gem::Version
|
319
|
-
version:
|
319
|
+
version: '0'
|
320
320
|
requirements: []
|
321
321
|
rubygems_version: 3.1.2
|
322
|
-
signing_key:
|
322
|
+
signing_key:
|
323
323
|
specification_version: 4
|
324
324
|
summary: GOV.UK-compliant Rails form builder
|
325
325
|
test_files: []
|