govuk_design_system_formbuilder 2.0.0b3 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +48 -24
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +13 -2
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +9 -8
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +10 -5
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +13 -7
- data/lib/govuk_design_system_formbuilder/traits/input.rb +42 -6
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fe5519859df526162a3594076aef6a37c0275990026f62fa1455b9918cea36c
|
4
|
+
data.tar.gz: 31ead896758013f7586eb0d4e98e533c6a2bb3da9470e5cd573db2d845755dc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05d32a227069f1adc8c64ba76e22d025629a419df6b714e369595342be29c8c5ac6547f39921fc62a78141dc6eda7d449c9c9335a01313661bb93602b2803203
|
7
|
+
data.tar.gz: cadc9b2ca35ffc8ac68cdb7a8c9f4bd4551e5ac8d8de5b2508f03a313069d60b89cb40a65a6e83cbd5a5b7eb834257ef0984d7901fa811e3ec23184a0cff998c
|
data/README.md
CHANGED
@@ -7,41 +7,32 @@
|
|
7
7
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/fde73b5dc9476197281b/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/test_coverage)
|
8
8
|
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=DFE-Digital/govuk_design_system_formbuilder)](https://dependabot.com)
|
9
9
|
[![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk_design_system_formbuilder)](https://github.com/DFE-Digital/govuk_design_system_formbuilder/blob/master/LICENSE)
|
10
|
-
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.
|
10
|
+
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.9.1-brightgreen)](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
|
[![Netlify Status](https://api.netlify.com/api/v1/badges/d4c50b8d-6ca3-4797-9ab3-6e0731c72b44/deploy-status)](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',
|
@@ -26,6 +26,8 @@ module GOVUKDesignSystemFormBuilder
|
|
26
26
|
# @param form_group [Hash] configures the form group
|
27
27
|
# @option form_group classes [Array,String] sets the form group's classes
|
28
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+
|
29
31
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
30
32
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
31
33
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -49,8 +51,8 @@ module GOVUKDesignSystemFormBuilder
|
|
49
51
|
# = f.govuk_text_field :callsign,
|
50
52
|
# label: -> { tag.h3('Call-sign') }
|
51
53
|
#
|
52
|
-
def govuk_text_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
53
|
-
Elements::Inputs::Text.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
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
|
54
56
|
end
|
55
57
|
|
56
58
|
# Generates a input of type +tel+
|
@@ -76,6 +78,8 @@ module GOVUKDesignSystemFormBuilder
|
|
76
78
|
# @param form_group [Hash] configures the form group
|
77
79
|
# @option form_group classes [Array,String] sets the form group's classes
|
78
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+
|
79
83
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
80
84
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
81
85
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -100,8 +104,8 @@ module GOVUKDesignSystemFormBuilder
|
|
100
104
|
# = f.govuk_phone_field :work_number,
|
101
105
|
# label: -> { tag.h3('Work number') }
|
102
106
|
#
|
103
|
-
def govuk_phone_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
104
|
-
Elements::Inputs::Phone.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
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
|
105
109
|
end
|
106
110
|
|
107
111
|
# Generates a input of type +email+
|
@@ -127,6 +131,8 @@ module GOVUKDesignSystemFormBuilder
|
|
127
131
|
# @param form_group [Hash] configures the form group
|
128
132
|
# @option form_group classes [Array,String] sets the form group's classes
|
129
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+
|
130
136
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
131
137
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
132
138
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -149,8 +155,8 @@ module GOVUKDesignSystemFormBuilder
|
|
149
155
|
# = f.govuk_email_field :personal_email,
|
150
156
|
# label: -> { tag.h3('Personal email address') }
|
151
157
|
#
|
152
|
-
def govuk_email_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
153
|
-
Elements::Inputs::Email.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
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
|
154
160
|
end
|
155
161
|
|
156
162
|
# Generates a input of type +password+
|
@@ -176,6 +182,8 @@ module GOVUKDesignSystemFormBuilder
|
|
176
182
|
# @param form_group [Hash] configures the form group
|
177
183
|
# @option form_group classes [Array,String] sets the form group's classes
|
178
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+
|
179
187
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
180
188
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
181
189
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -197,8 +205,8 @@ module GOVUKDesignSystemFormBuilder
|
|
197
205
|
# = f.govuk_password_field :passcode,
|
198
206
|
# label: -> { tag.h3('What is your secret pass code?') }
|
199
207
|
#
|
200
|
-
def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, form_group: {}, caption: {}, **kwargs, &block)
|
201
|
-
Elements::Inputs::Password.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
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
|
202
210
|
end
|
203
211
|
|
204
212
|
# Generates a input of type +url+
|
@@ -224,6 +232,8 @@ module GOVUKDesignSystemFormBuilder
|
|
224
232
|
# @param form_group [Hash] configures the form group
|
225
233
|
# @option form_group classes [Array,String] sets the form group's classes
|
226
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+
|
227
237
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
228
238
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
229
239
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -246,8 +256,8 @@ module GOVUKDesignSystemFormBuilder
|
|
246
256
|
# = f.govuk_url_field :work_website,
|
247
257
|
# label: -> { tag.h3("Enter your company's website") }
|
248
258
|
#
|
249
|
-
def govuk_url_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
250
|
-
Elements::Inputs::URL.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
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
|
251
261
|
end
|
252
262
|
|
253
263
|
# Generates a input of type +number+
|
@@ -273,6 +283,8 @@ module GOVUKDesignSystemFormBuilder
|
|
273
283
|
# @param form_group [Hash] configures the form group
|
274
284
|
# @option form_group classes [Array,String] sets the form group's classes
|
275
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+
|
276
288
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
277
289
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
278
290
|
# @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
|
@@ -298,8 +310,8 @@ module GOVUKDesignSystemFormBuilder
|
|
298
310
|
# = f.govuk_url_field :personal_best_over_100m,
|
299
311
|
# label: -> { tag.h3("How many seconds does it take you to run 100m?") }
|
300
312
|
#
|
301
|
-
def govuk_number_field(attribute_name, hint: {}, label: {}, caption: {}, width: nil, form_group: {}, **kwargs, &block)
|
302
|
-
Elements::Inputs::Number.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, width: width, form_group: form_group, **kwargs, &block).html
|
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
|
303
315
|
end
|
304
316
|
|
305
317
|
# Generates a +textarea+ element with a label, optional hint. Also offers
|
@@ -447,7 +459,7 @@ module GOVUKDesignSystemFormBuilder
|
|
447
459
|
# @param classes [Array,String] Classes to add to the radio button container.
|
448
460
|
# @option legend text [String] the fieldset legend's text content
|
449
461
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
450
|
-
# @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+.
|
451
463
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
452
464
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
453
465
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
@@ -526,7 +538,7 @@ module GOVUKDesignSystemFormBuilder
|
|
526
538
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
527
539
|
# @option legend text [String] the fieldset legend's text content
|
528
540
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
529
|
-
# @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+.
|
530
542
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
531
543
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
532
544
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
@@ -623,7 +635,7 @@ module GOVUKDesignSystemFormBuilder
|
|
623
635
|
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
624
636
|
# @option legend text [String] the fieldset legend's text content
|
625
637
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
626
|
-
# @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+.
|
627
639
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
628
640
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
629
641
|
# @option caption text [String] the caption text
|
@@ -701,7 +713,7 @@ module GOVUKDesignSystemFormBuilder
|
|
701
713
|
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
702
714
|
# @option legend text [String] the fieldset legend's text content
|
703
715
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
704
|
-
# @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+.
|
705
717
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
706
718
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
707
719
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
@@ -710,6 +722,8 @@ module GOVUKDesignSystemFormBuilder
|
|
710
722
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
711
723
|
# @param classes [Array,String] Classes to add to the checkbox container.
|
712
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>)
|
713
727
|
# @option form_group classes [Array,String] sets the form group's classes
|
714
728
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
715
729
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
@@ -725,7 +739,7 @@ module GOVUKDesignSystemFormBuilder
|
|
725
739
|
# = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
|
726
740
|
# = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
|
727
741
|
#
|
728
|
-
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)
|
729
743
|
Containers::CheckBoxesFieldset.new(
|
730
744
|
self,
|
731
745
|
object_name,
|
@@ -736,6 +750,7 @@ module GOVUKDesignSystemFormBuilder
|
|
736
750
|
small: small,
|
737
751
|
classes: classes,
|
738
752
|
form_group: form_group,
|
753
|
+
multiple: multiple,
|
739
754
|
&block
|
740
755
|
).html
|
741
756
|
end
|
@@ -744,6 +759,7 @@ module GOVUKDesignSystemFormBuilder
|
|
744
759
|
#
|
745
760
|
# @param attribute_name [Symbol] The name of the attribute
|
746
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
|
747
763
|
# @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
|
748
764
|
# supplied the hint will be wrapped in a +div+ instead of a +span+
|
749
765
|
# @option hint text [String] the hint text
|
@@ -766,12 +782,13 @@ module GOVUKDesignSystemFormBuilder
|
|
766
782
|
# label: { text: 'Do you agree with our terms and conditions?' },
|
767
783
|
# hint: { text: 'You will not be able to proceed unless you do' }
|
768
784
|
#
|
769
|
-
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)
|
770
786
|
Elements::CheckBoxes::FieldsetCheckBox.new(
|
771
787
|
self,
|
772
788
|
object_name,
|
773
789
|
attribute_name,
|
774
790
|
value,
|
791
|
+
unchecked_value,
|
775
792
|
hint: hint,
|
776
793
|
label: label,
|
777
794
|
link_errors: link_errors,
|
@@ -799,6 +816,8 @@ module GOVUKDesignSystemFormBuilder
|
|
799
816
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
800
817
|
# @note Only the first additional button or link (passed in via a block) will be given the
|
801
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
|
802
821
|
# @see https://design-system.service.gov.uk/components/button/#stop-users-from-accidentally-sending-information-more-than-once
|
803
822
|
# GOV.UK double click prevention
|
804
823
|
#
|
@@ -823,7 +842,7 @@ module GOVUKDesignSystemFormBuilder
|
|
823
842
|
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
824
843
|
# @option legend text [String] the fieldset legend's text content
|
825
844
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
826
|
-
# @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+.
|
827
846
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
828
847
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
829
848
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
@@ -861,13 +880,18 @@ module GOVUKDesignSystemFormBuilder
|
|
861
880
|
# part of the form that contains the error
|
862
881
|
#
|
863
882
|
# @param title [String] the error summary heading
|
883
|
+
# @param link_base_errors_to [Symbol,String] set the field that errors on +:base+ are linked
|
884
|
+
# to, as there won't be a field representing the object base.
|
885
|
+
#
|
886
|
+
# @note Only the first error in the +#errors+ array for each attribute will
|
887
|
+
# be included.
|
864
888
|
#
|
865
889
|
# @example An error summary with a custom title
|
866
890
|
# = f.govuk_error_summary 'Uh-oh, spaghettios'
|
867
891
|
#
|
868
892
|
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
|
869
|
-
def govuk_error_summary(title = config.default_error_summary_title)
|
870
|
-
Elements::ErrorSummary.new(self, object_name, title).html
|
893
|
+
def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil)
|
894
|
+
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to).html
|
871
895
|
end
|
872
896
|
|
873
897
|
# Generates a fieldset containing the contents of the block
|
@@ -876,7 +900,7 @@ module GOVUKDesignSystemFormBuilder
|
|
876
900
|
# @param described_by [Array<String>] the ids of the elements that describe this fieldset, usually hints and errors
|
877
901
|
# @option legend text [String] the fieldset legend's text content
|
878
902
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
879
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
903
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
880
904
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
881
905
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
882
906
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
@@ -885,13 +909,13 @@ module GOVUKDesignSystemFormBuilder
|
|
885
909
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
886
910
|
#
|
887
911
|
# @example A fieldset containing address fields
|
888
|
-
# = f.govuk_fieldset legend: { text: 'Address' }
|
912
|
+
# = f.govuk_fieldset legend: { text: 'Address' } do
|
889
913
|
# = f.govuk_text_field :street
|
890
914
|
# = f.govuk_text_field :town
|
891
915
|
# = f.govuk_text_field :city
|
892
916
|
#
|
893
917
|
# @example A fieldset with the legend as a proc
|
894
|
-
# = f.govuk_fieldset legend: -> { tag.h3('Skills') }
|
918
|
+
# = f.govuk_fieldset legend: -> { tag.h3('Skills') } do
|
895
919
|
# = f.govuk_text_area :physical
|
896
920
|
# = f.govuk_text_area :mental
|
897
921
|
#
|
@@ -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,
|
@@ -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
|
@@ -66,7 +67,7 @@ module GOVUKDesignSystemFormBuilder
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def hint_options
|
69
|
-
{ checkbox: true }
|
70
|
+
{ value: @value, checkbox: true }
|
70
71
|
end
|
71
72
|
|
72
73
|
def conditional_classes
|
@@ -3,10 +3,11 @@ module GOVUKDesignSystemFormBuilder
|
|
3
3
|
class ErrorSummary < Base
|
4
4
|
include Traits::Error
|
5
5
|
|
6
|
-
def initialize(builder, object_name, title)
|
7
|
-
@builder
|
8
|
-
@object_name
|
9
|
-
@title
|
6
|
+
def initialize(builder, object_name, title, link_base_errors_to:)
|
7
|
+
@builder = builder
|
8
|
+
@object_name = object_name
|
9
|
+
@title = title
|
10
|
+
@link_base_errors_to = link_base_errors_to
|
10
11
|
end
|
11
12
|
|
12
13
|
def html
|
@@ -54,7 +55,11 @@ module GOVUKDesignSystemFormBuilder
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def field_id(attribute)
|
57
|
-
|
58
|
+
if attribute.eql?(:base) && @link_base_errors_to.present?
|
59
|
+
build_id('field', attribute_name: @link_base_errors_to)
|
60
|
+
else
|
61
|
+
build_id('field-error', attribute_name: attribute)
|
62
|
+
end
|
58
63
|
end
|
59
64
|
|
60
65
|
def summary_title_id
|
@@ -11,7 +11,7 @@ module GOVUKDesignSystemFormBuilder
|
|
11
11
|
|
12
12
|
case legend
|
13
13
|
when NilClass
|
14
|
-
|
14
|
+
# do nothing
|
15
15
|
when Proc
|
16
16
|
@raw = capture { legend.call }
|
17
17
|
when Hash
|
@@ -23,7 +23,7 @@ module GOVUKDesignSystemFormBuilder
|
|
23
23
|
@caption = caption
|
24
24
|
end
|
25
25
|
else
|
26
|
-
fail(ArgumentError, %(legend must be a Proc or Hash))
|
26
|
+
fail(ArgumentError, %(legend must be a NilClass, Proc or Hash))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -38,12 +38,18 @@ module GOVUKDesignSystemFormBuilder
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def content
|
41
|
-
return
|
41
|
+
return unless active?
|
42
42
|
|
43
|
-
tag.legend(class: classes, **@html_attributes)
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
47
53
|
end
|
48
54
|
end
|
49
55
|
|
@@ -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.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-28 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
|
@@ -314,9 +314,9 @@ 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
322
|
signing_key:
|