govuk_design_system_formbuilder 2.7.0 → 2.7.4
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 +21 -7
- data/lib/govuk_design_system_formbuilder/base.rb +1 -1
- data/lib/govuk_design_system_formbuilder/builder.rb +29 -7
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +1 -1
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +2 -1
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +1 -1
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +1 -1
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +3 -2
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +11 -4
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb +5 -1
- data/lib/govuk_design_system_formbuilder/elements/collection_select.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +13 -2
- data/lib/govuk_design_system_formbuilder/elements/file.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +2 -0
- data/lib/govuk_design_system_formbuilder/elements/label.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +5 -1
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +2 -2
- data/lib/govuk_design_system_formbuilder/elements/select.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +1 -1
- data/lib/govuk_design_system_formbuilder/presenters/error_summary.rb +29 -0
- data/lib/govuk_design_system_formbuilder/traits/fieldset_item.rb +4 -4
- data/lib/govuk_design_system_formbuilder/traits/html_attributes.rb +1 -1
- data/lib/govuk_design_system_formbuilder/traits/input.rb +1 -1
- data/lib/govuk_design_system_formbuilder/traits/select.rb +1 -1
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- data/lib/govuk_design_system_formbuilder.rb +16 -5
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e957bab838013fdafade2624efb663ab4f40befc05313a3f676e1db7db50ee5
|
|
4
|
+
data.tar.gz: f9eaf97153026e3f14c24158013276315a4464a0fd5216b7ce80d36b3c5eda02
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27a67e5dfa2a13da2abc4769f539b618fe091f0840b51132e5fac32b5f90285dbdddcf4b6516e562b83fc7b3d0036fdd62dd70c0609204e015172aa14e6fb3d4
|
|
7
|
+
data.tar.gz: b9fb370f1e5e3eaeb08fec860a48f03a4ab3b6c38613a90c7cb3d12e906298d26187b268c3a7befacafe1d36a5ab6452a2eac8b598c6d379e559f7ccb31fb101
|
data/README.md
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
# GOV.UK Design System Form Builder for Rails
|
|
2
2
|
|
|
3
|
-
[](https://github.com/DFE-Digital/govuk-formbuilder/actions)
|
|
4
|
+
[](https://codeclimate.com/github/DFE-Digital/govuk-formbuilder/maintainability)
|
|
5
5
|
[](https://badge.fury.io/rb/govuk_design_system_formbuilder)
|
|
6
6
|
[](https://rubygems.org/gems/govuk_design_system_formbuilder)
|
|
7
|
-
[](https://www.ruby-lang.org/en/downloads/)
|
|
7
|
+
[](https://codeclimate.com/github/DFE-Digital/govuk-formbuilder/test_coverage)
|
|
8
|
+
[](https://github.com/DFE-Digital/govuk-formbuilder/blob/master/LICENSE)
|
|
9
|
+
[](https://design-system.service.gov.uk)
|
|
10
|
+
[](https://www.ruby-lang.org/en/downloads/)
|
|
12
11
|
[](https://weblog.rubyonrails.org/releases/)
|
|
13
12
|
|
|
14
13
|
This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
|
|
@@ -129,6 +128,21 @@ To help keep the logs clean and tidy, please configure git to use your full name
|
|
|
129
128
|
git config --global user.name "Julius Hibbert"
|
|
130
129
|
```
|
|
131
130
|
|
|
131
|
+
## Services using this library
|
|
132
|
+
|
|
133
|
+
Approximately [40 services use this library](https://github.com/DFE-Digital/govuk-formbuilder/network/dependents),
|
|
134
|
+
here are a few from the <abbr title="Department for Education">DfE</abbr>, <abbr title="Ministry of Justice">MoJ</abbr>, and
|
|
135
|
+
<abbr title="Department for Business, Energy & Industrial Strategy">BEIS</abbr>.
|
|
136
|
+
|
|
137
|
+
* [Apply for teacher training](https://www.github.com/DFE-Digital/apply-for-teacher-training)
|
|
138
|
+
* [Teaching Vacancies](https://www.github.com/DFE-Digital/teaching-vacancies)
|
|
139
|
+
* [Get a teacher training adviser](https://www.github.com/DFE-Digital/get-teacher-training-adviser-service/)
|
|
140
|
+
* [Claim for crown court defence](https://www.github.com/ministryofjustice/Claim-for-Crown-Court-Defence)
|
|
141
|
+
* [Appeal to the tax tribunal](https://www.github.com/ministryofjustice/tax-tribunals-datacapture)
|
|
142
|
+
* [Apply to court about child arrangements](https://www.github.com/ministryofjustice/c100-application)
|
|
143
|
+
* [Trade Tariff duty calculator](https://www.github.com/trade-tariff/trade-tariff-duty-calculator)
|
|
144
|
+
* [Report your official development assistance](https://www.github.com/UKGovernmentBEIS/beis-report-official-development-assistance)
|
|
145
|
+
|
|
132
146
|
## Thanks 👩🏽⚖️
|
|
133
147
|
|
|
134
148
|
This project was inspired by [Ministry of Justice's GovukElementsFormBuilder](https://github.com/ministryofjustice/govuk_elements_form_builder),
|
|
@@ -471,9 +471,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
471
471
|
# @note Unlike the Rails +#collection_radio_buttons+ helper, this version can also insert
|
|
472
472
|
# hints per item in the collection by supplying a +:hint_method+
|
|
473
473
|
#
|
|
474
|
-
# @note +:bold_labels+,
|
|
475
|
-
#
|
|
476
|
-
#
|
|
474
|
+
# @note +:bold_labels+, is +nil+ (falsy) by default. When a +:hint_method+
|
|
475
|
+
# is provided it will become +true+ to make the label stand out more
|
|
476
|
+
# from the hint. The choice can be overridden with +true+ or +false+.
|
|
477
477
|
#
|
|
478
478
|
# @param attribute_name [Symbol] The name of the attribute
|
|
479
479
|
# @param collection [Enumerable<Object>] Options to be added to the +select+ element
|
|
@@ -538,7 +538,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
538
538
|
# :name,
|
|
539
539
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
|
540
540
|
#
|
|
541
|
-
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:
|
|
541
|
+
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: nil, classes: nil, include_hidden: config.default_collection_radio_buttons_include_hidden, form_group: {}, &block)
|
|
542
542
|
Elements::Radios::Collection.new(
|
|
543
543
|
self,
|
|
544
544
|
object_name,
|
|
@@ -813,6 +813,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
813
813
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
814
814
|
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
815
815
|
# @param multiple [Boolean] controls whether the check box is part of a collection or represents a single attribute
|
|
816
|
+
# @param exclusive [Boolean] sets the checkbox so that when checked none of its siblings can be too. Usually
|
|
817
|
+
# used for the 'None of these apply to me' option found beneath a {#govuk_check_box_divider}.
|
|
816
818
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
817
819
|
# @param block [Block] any HTML passed in will form the contents of the fieldset
|
|
818
820
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
@@ -825,7 +827,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
825
827
|
# label: { text: 'Do you agree with our terms and conditions?' },
|
|
826
828
|
# hint: { text: 'You will not be able to proceed unless you do' }
|
|
827
829
|
#
|
|
828
|
-
def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, **kwargs, &block)
|
|
830
|
+
def govuk_check_box(attribute_name, value, unchecked_value = false, hint: {}, label: {}, link_errors: false, multiple: true, exclusive: false, **kwargs, &block)
|
|
829
831
|
Elements::CheckBoxes::FieldsetCheckBox.new(
|
|
830
832
|
self,
|
|
831
833
|
object_name,
|
|
@@ -836,11 +838,24 @@ module GOVUKDesignSystemFormBuilder
|
|
|
836
838
|
label: label,
|
|
837
839
|
link_errors: link_errors,
|
|
838
840
|
multiple: multiple,
|
|
841
|
+
exclusive: exclusive,
|
|
839
842
|
**kwargs,
|
|
840
843
|
&block
|
|
841
844
|
).html
|
|
842
845
|
end
|
|
843
846
|
|
|
847
|
+
# Inserts a text divider into a list of check boxes
|
|
848
|
+
#
|
|
849
|
+
# @param text [String] The divider text
|
|
850
|
+
# @note This should only be used from within a {#govuk_check_boxes_fieldset}
|
|
851
|
+
# @see https://design-system.service.gov.uk/components/checkboxes/#add-an-option-for-none- GOV.UK check boxes with a text divider
|
|
852
|
+
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
853
|
+
# @example A custom divider
|
|
854
|
+
# = govuk_check_box_divider 'On the other hand'
|
|
855
|
+
def govuk_check_box_divider(text = config.default_check_box_divider_text)
|
|
856
|
+
tag.div(text, class: %w(govuk-checkboxes__divider))
|
|
857
|
+
end
|
|
858
|
+
|
|
844
859
|
# Generates a submit button, green by default
|
|
845
860
|
#
|
|
846
861
|
# @param text [String,Proc] the button text. When a +Proc+ is provided its contents will be rendered within the button element
|
|
@@ -936,6 +951,13 @@ module GOVUKDesignSystemFormBuilder
|
|
|
936
951
|
# which they were defined on the model).
|
|
937
952
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the error summary +div+ element
|
|
938
953
|
# @param block [Block] arbitrary HTML that will be rendered between title and error message list
|
|
954
|
+
# @param presenter [Class,Object] the class or object that is responsible for formatting a list of error
|
|
955
|
+
# messages that will be rendered in the summary.
|
|
956
|
+
#
|
|
957
|
+
# * When a class is specified it will be instantiated with the object's errors in the +object.errors.messages+ format.
|
|
958
|
+
# * When an object is specified it will be used as-is.
|
|
959
|
+
#
|
|
960
|
+
# The object must implement +#formatted_error_messages+, see {Presenters::ErrorSummaryPresenter} for more details.
|
|
939
961
|
#
|
|
940
962
|
# @note Only the first error in the +#errors+ array for each attribute will
|
|
941
963
|
# be included.
|
|
@@ -944,8 +966,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
944
966
|
# = f.govuk_error_summary 'Uh-oh, spaghettios'
|
|
945
967
|
#
|
|
946
968
|
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
|
|
947
|
-
def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil, order: nil, **kwargs, &block)
|
|
948
|
-
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, order: order, **kwargs, &block).html
|
|
969
|
+
def govuk_error_summary(title = config.default_error_summary_title, presenter: config.default_error_summary_presenter, link_base_errors_to: nil, order: nil, **kwargs, &block)
|
|
970
|
+
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, order: order, presenter: presenter, **kwargs, &block).html
|
|
949
971
|
end
|
|
950
972
|
|
|
951
973
|
# Generates a fieldset containing the contents of the block
|
|
@@ -5,6 +5,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
5
5
|
include Traits::Hint
|
|
6
6
|
|
|
7
7
|
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, small:, classes:, form_group:, multiple:, &block)
|
|
8
|
+
fail LocalJumpError, 'no block given' unless block_given?
|
|
9
|
+
|
|
8
10
|
super(builder, object_name, attribute_name, &block)
|
|
9
11
|
|
|
10
12
|
@legend = legend
|
|
@@ -14,7 +16,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
14
16
|
@classes = classes
|
|
15
17
|
@form_group = form_group
|
|
16
18
|
@multiple = multiple
|
|
17
|
-
@block_content = capture { block.call }
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
def html
|
|
@@ -5,7 +5,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
5
5
|
include Traits::Error
|
|
6
6
|
|
|
7
7
|
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, inline:, small:, classes:, form_group:, &block)
|
|
8
|
-
|
|
8
|
+
fail LocalJumpError, 'no block given' unless block_given?
|
|
9
|
+
|
|
10
|
+
super(builder, object_name, attribute_name, &block)
|
|
9
11
|
|
|
10
12
|
@inline = inline
|
|
11
13
|
@small = small
|
|
@@ -14,7 +16,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
14
16
|
@hint = hint
|
|
15
17
|
@classes = classes
|
|
16
18
|
@form_group = form_group
|
|
17
|
-
@block_content = capture { block.call }
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
def html
|
|
@@ -7,8 +7,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
7
7
|
include Traits::HTMLAttributes
|
|
8
8
|
include Traits::FieldsetItem
|
|
9
9
|
|
|
10
|
-
def initialize(builder, object_name, attribute_name, value, unchecked_value, label:, hint:, link_errors:, multiple:, **kwargs, &block)
|
|
11
|
-
super(builder, object_name, attribute_name)
|
|
10
|
+
def initialize(builder, object_name, attribute_name, value, unchecked_value, label:, hint:, link_errors:, multiple:, exclusive:, **kwargs, &block)
|
|
11
|
+
super(builder, object_name, attribute_name, &block)
|
|
12
12
|
|
|
13
13
|
@value = value
|
|
14
14
|
@unchecked_value = unchecked_value
|
|
@@ -17,8 +17,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
17
17
|
@multiple = multiple
|
|
18
18
|
@link_errors = link_errors
|
|
19
19
|
@html_attributes = kwargs
|
|
20
|
+
@exclusive = exclusive
|
|
20
21
|
|
|
21
|
-
conditional_content(
|
|
22
|
+
conditional_content(@block_content)
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
private
|
|
@@ -28,12 +29,18 @@ module GOVUKDesignSystemFormBuilder
|
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
def input
|
|
31
|
-
@builder.check_box(@attribute_name, attributes(@html_attributes), @value, @unchecked_value)
|
|
32
|
+
@builder.check_box(@attribute_name, attributes(@html_attributes.deep_merge(exclusive_options)), @value, @unchecked_value)
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def fieldset_options
|
|
35
36
|
{ checkbox: true }
|
|
36
37
|
end
|
|
38
|
+
|
|
39
|
+
def exclusive_options
|
|
40
|
+
return {} unless @exclusive
|
|
41
|
+
|
|
42
|
+
{ data: { behaviour: 'exclusive' } }
|
|
43
|
+
end
|
|
37
44
|
end
|
|
38
45
|
end
|
|
39
46
|
end
|
|
@@ -16,7 +16,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
16
16
|
|
|
17
17
|
def html
|
|
18
18
|
@checkbox.label(for: field_id(link_errors: @link_errors), class: label_classes) do
|
|
19
|
-
|
|
19
|
+
label_content.to_s
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -25,6 +25,10 @@ module GOVUKDesignSystemFormBuilder
|
|
|
25
25
|
def label_classes
|
|
26
26
|
%w(label checkboxes__label).prefix(brand)
|
|
27
27
|
end
|
|
28
|
+
|
|
29
|
+
def label_content
|
|
30
|
+
[localised_text(:label), @checkbox.text, @value].find(&:presence)
|
|
31
|
+
end
|
|
28
32
|
end
|
|
29
33
|
end
|
|
30
34
|
end
|
|
@@ -40,7 +40,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
40
40
|
{
|
|
41
41
|
id: field_id(link_errors: true),
|
|
42
42
|
class: classes,
|
|
43
|
-
aria: { describedby:
|
|
43
|
+
aria: { describedby: combine_references(hint_id, error_id, supplemental_id) }
|
|
44
44
|
}
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -4,13 +4,14 @@ module GOVUKDesignSystemFormBuilder
|
|
|
4
4
|
include Traits::Error
|
|
5
5
|
include Traits::HTMLAttributes
|
|
6
6
|
|
|
7
|
-
def initialize(builder, object_name, title, link_base_errors_to:, order:, **kwargs, &block)
|
|
7
|
+
def initialize(builder, object_name, title, link_base_errors_to:, order:, presenter:, **kwargs, &block)
|
|
8
8
|
super(builder, object_name, nil, &block)
|
|
9
9
|
|
|
10
10
|
@title = title
|
|
11
11
|
@link_base_errors_to = link_base_errors_to
|
|
12
12
|
@html_attributes = kwargs
|
|
13
13
|
@order = order
|
|
14
|
+
@presenter = presenter
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def html
|
|
@@ -33,7 +34,17 @@ module GOVUKDesignSystemFormBuilder
|
|
|
33
34
|
|
|
34
35
|
def list
|
|
35
36
|
tag.ul(class: [%(#{brand}-list), summary_class('list')]) do
|
|
36
|
-
safe_join(
|
|
37
|
+
safe_join(presenter.formatted_error_messages.map { |args| list_item(*args) })
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# If the provided @presenter is a class, instantiate it with the sorted
|
|
42
|
+
# error_messages from our object. Otherwise (if it's any other object),
|
|
43
|
+
# treat it like a presenter
|
|
44
|
+
def presenter
|
|
45
|
+
(@presenter.is_a?(Class) ? @presenter.new(error_messages) : @presenter).tap do |p|
|
|
46
|
+
fail(ArgumentError, "error summary presenter doesn't implement #formatted_error_messages") unless
|
|
47
|
+
p.respond_to?(:formatted_error_messages)
|
|
37
48
|
end
|
|
38
49
|
end
|
|
39
50
|
|
|
@@ -35,7 +35,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
35
35
|
{
|
|
36
36
|
id: field_id(link_errors: true),
|
|
37
37
|
class: classes,
|
|
38
|
-
aria: { describedby:
|
|
38
|
+
aria: { describedby: combine_references(hint_id, error_id, supplemental_id) }
|
|
39
39
|
}
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -50,7 +50,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def retrieve_text(option_text, hidden)
|
|
53
|
-
text = [option_text, localised_text(:label), @attribute_name.capitalize].
|
|
53
|
+
text = [option_text, localised_text(:label), @attribute_name.capitalize].find(&:presence)
|
|
54
54
|
|
|
55
55
|
if hidden
|
|
56
56
|
tag.span(text, class: %(#{brand}-visually-hidden))
|
|
@@ -45,7 +45,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def retrieve_text(supplied_text)
|
|
48
|
-
[supplied_text, localised_text(:legend), @attribute_name&.capitalize].
|
|
48
|
+
[supplied_text, localised_text(:legend), @attribute_name&.capitalize].find(&:presence)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def classes
|
|
@@ -21,7 +21,11 @@ module GOVUKDesignSystemFormBuilder
|
|
|
21
21
|
@classes = classes
|
|
22
22
|
@form_group = form_group
|
|
23
23
|
@include_hidden = include_hidden
|
|
24
|
-
@bold_labels =
|
|
24
|
+
@bold_labels = if bold_labels.nil?
|
|
25
|
+
hint_method.present?
|
|
26
|
+
else
|
|
27
|
+
bold_labels
|
|
28
|
+
end
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
def html
|
|
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
8
8
|
include Traits::FieldsetItem
|
|
9
9
|
|
|
10
10
|
def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, **kwargs, &block)
|
|
11
|
-
super(builder, object_name, attribute_name)
|
|
11
|
+
super(builder, object_name, attribute_name, &block)
|
|
12
12
|
|
|
13
13
|
@value = value
|
|
14
14
|
@label = label
|
|
@@ -16,7 +16,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
16
16
|
@link_errors = has_errors? && link_errors
|
|
17
17
|
@html_attributes = kwargs
|
|
18
18
|
|
|
19
|
-
conditional_content(
|
|
19
|
+
conditional_content(@block_content)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
private
|
|
@@ -53,7 +53,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
53
53
|
id: field_id(link_errors: true),
|
|
54
54
|
class: classes,
|
|
55
55
|
rows: @rows,
|
|
56
|
-
aria: { describedby:
|
|
56
|
+
aria: { describedby: combine_references(hint_id, error_id, supplemental_id, limit_description_id) },
|
|
57
57
|
}
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Presenters
|
|
2
|
+
# This is the default presenter for {GOVUKDesignSystemFormBuilder::Elements::ErrorSummary} and is
|
|
3
|
+
# intended to be easily replaceable should you have specific requirements that aren't met here.
|
|
4
|
+
#
|
|
5
|
+
# The basic behaviour is to always show the first error message. In Rails, error message order is
|
|
6
|
+
# determined by the order in which the validations run, but if you need to do any other transformation
|
|
7
|
+
# or concatenation, this is the place to do it.
|
|
8
|
+
class ErrorSummaryPresenter
|
|
9
|
+
# @param [Hash] error_messages the error message hash in a format that matches Rails'
|
|
10
|
+
# `object.errors.messages`, so the format should be:
|
|
11
|
+
#
|
|
12
|
+
# @example Input format:
|
|
13
|
+
# ErrorSummaryPresenter.new({ attribute_one: ["first error", "second error"], attribute_two: ["third error"] })
|
|
14
|
+
def initialize(error_messages)
|
|
15
|
+
@error_messages = error_messages
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Converts +@error_messages+ into an array of argument arrays that will be
|
|
19
|
+
# passed into {GOVUKDesignSystemFormBuilder::Elements::ErrorSummary#list_item}.
|
|
20
|
+
#
|
|
21
|
+
# @return [Array<Array(Symbol, String)>] array of attribute and message arrays
|
|
22
|
+
#
|
|
23
|
+
# @example Output format given the input above:
|
|
24
|
+
# [[:attribute_one, "first error"], [:attribute_two, "third error"]]
|
|
25
|
+
def formatted_error_messages
|
|
26
|
+
@error_messages.map { |attribute, messages| [attribute, messages.first] }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -4,7 +4,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
4
4
|
using PrefixableArray
|
|
5
5
|
|
|
6
6
|
def html
|
|
7
|
-
safe_join([item, @
|
|
7
|
+
safe_join([item, @conditional_content])
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
private
|
|
@@ -61,9 +61,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
61
61
|
build_id('conditional')
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
def conditional_content(
|
|
65
|
-
if
|
|
66
|
-
@
|
|
64
|
+
def conditional_content(block_content)
|
|
65
|
+
if block_content.present?
|
|
66
|
+
@conditional_content = conditional_container(block_content)
|
|
67
67
|
@conditional_id = conditional_id
|
|
68
68
|
end
|
|
69
69
|
end
|
|
@@ -4,7 +4,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
4
4
|
# Attributes eases working with default and custom attributes by:
|
|
5
5
|
# * deeply merging them so both the default (required) attributes are
|
|
6
6
|
# present
|
|
7
|
-
# * joins the arrays into strings to maintain Rails 6.0
|
|
7
|
+
# * joins the arrays into strings to maintain Rails 6.0.* compatibility
|
|
8
8
|
class Attributes
|
|
9
9
|
# Rather than attempt to combine these attributes, just overwrite the
|
|
10
10
|
# form internally-generated values with those that are passed in. This
|
|
@@ -48,7 +48,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
48
48
|
{
|
|
49
49
|
id: field_id(link_errors: true),
|
|
50
50
|
class: classes,
|
|
51
|
-
aria: { describedby:
|
|
51
|
+
aria: { describedby: combine_references(hint_id, error_id, supplemental_id) }
|
|
52
52
|
}
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'deep_merge/rails_compat'
|
|
2
2
|
require 'active_support/configurable'
|
|
3
3
|
|
|
4
|
-
[%w(refinements *.rb), %w(traits *.rb), %w(*.rb), %w(elements ** *.rb), %w(containers ** *.rb)]
|
|
4
|
+
[%w(presenters *.rb), %w(refinements *.rb), %w(traits *.rb), %w(*.rb), %w(elements ** *.rb), %w(containers ** *.rb)]
|
|
5
5
|
.flat_map { |matcher| Dir.glob(File.join(__dir__, 'govuk_design_system_formbuilder', *matcher)) }
|
|
6
6
|
.each { |file| require file }
|
|
7
7
|
|
|
@@ -27,20 +27,29 @@ module GOVUKDesignSystemFormBuilder
|
|
|
27
27
|
# * +:default_submit_button_text+ sets the value assigned to +govuk_submit+,
|
|
28
28
|
# defaults to 'Continue'.
|
|
29
29
|
#
|
|
30
|
+
# * +:default_radio_divider_text+ sets the text automatically added to the
|
|
31
|
+
# radio button divider, defaults to 'or'
|
|
32
|
+
#
|
|
33
|
+
# * +:default_check_box_divider_text+ sets the text automatically added to the
|
|
34
|
+
# checkbox divider, defaults to 'or'
|
|
35
|
+
#
|
|
30
36
|
# * +:default_submit_button_text+ sets the text used to divide the last radio
|
|
31
37
|
# button in radio button fieldsets. As per the GOV.UK Design System spec,
|
|
32
38
|
# it defaults to 'or'.
|
|
33
39
|
#
|
|
34
|
-
# * +:default_error_summary_title+ sets the text used in error summary
|
|
35
|
-
# blocks. As per the GOV.UK Design System spec, it defaults to
|
|
36
|
-
# 'There is a problem'.
|
|
37
|
-
#
|
|
38
40
|
# * +:default_collection_check_boxes_include_hidden+ controls whether or not
|
|
39
41
|
# a hidden field is added when rendering a collection of check boxes
|
|
40
42
|
#
|
|
41
43
|
# * +:default_collection_radio_buttons_include_hidden+ controls whether or not
|
|
42
44
|
# a hidden field is added when rendering a collection of radio buttons
|
|
43
45
|
#
|
|
46
|
+
# * +:default_error_summary_title+ sets the text used in error summary
|
|
47
|
+
# blocks. As per the GOV.UK Design System spec, it defaults to
|
|
48
|
+
# 'There is a problem'.
|
|
49
|
+
#
|
|
50
|
+
# * +:default_error_summary_presenter+ the class that's instantiated when
|
|
51
|
+
# rendering an error summary and formats the messages for each attribute
|
|
52
|
+
#
|
|
44
53
|
# * +:default_error_summary_error_order_method+ is the method that the library
|
|
45
54
|
# will check for on the bound object to see whether or not to try ordering the
|
|
46
55
|
# error messages
|
|
@@ -65,7 +74,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
65
74
|
default_caption_size: 'm',
|
|
66
75
|
default_submit_button_text: 'Continue',
|
|
67
76
|
default_radio_divider_text: 'or',
|
|
77
|
+
default_check_box_divider_text: 'or',
|
|
68
78
|
default_error_summary_title: 'There is a problem',
|
|
79
|
+
default_error_summary_presenter: Presenters::ErrorSummaryPresenter,
|
|
69
80
|
default_error_summary_error_order_method: nil,
|
|
70
81
|
default_collection_check_boxes_include_hidden: true,
|
|
71
82
|
default_collection_radio_buttons_include_hidden: true,
|
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.7.
|
|
4
|
+
version: 2.7.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter Yates
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: deep_merge
|
|
@@ -274,14 +274,14 @@ dependencies:
|
|
|
274
274
|
requirements:
|
|
275
275
|
- - "~>"
|
|
276
276
|
- !ruby/object:Gem::Version
|
|
277
|
-
version: 0.
|
|
277
|
+
version: 0.22.0
|
|
278
278
|
type: :development
|
|
279
279
|
prerelease: false
|
|
280
280
|
version_requirements: !ruby/object:Gem::Requirement
|
|
281
281
|
requirements:
|
|
282
282
|
- - "~>"
|
|
283
283
|
- !ruby/object:Gem::Version
|
|
284
|
-
version: 0.
|
|
284
|
+
version: 0.22.0
|
|
285
285
|
description: A Rails form builder that generates form inputs adhering to the GOV.UK
|
|
286
286
|
Design System
|
|
287
287
|
email:
|
|
@@ -331,6 +331,7 @@ files:
|
|
|
331
331
|
- lib/govuk_design_system_formbuilder/elements/select.rb
|
|
332
332
|
- lib/govuk_design_system_formbuilder/elements/submit.rb
|
|
333
333
|
- lib/govuk_design_system_formbuilder/elements/text_area.rb
|
|
334
|
+
- lib/govuk_design_system_formbuilder/presenters/error_summary.rb
|
|
334
335
|
- lib/govuk_design_system_formbuilder/proxy.rb
|
|
335
336
|
- lib/govuk_design_system_formbuilder/refinements/prefixable_array.rb
|
|
336
337
|
- lib/govuk_design_system_formbuilder/traits/caption.rb
|
|
@@ -354,6 +355,7 @@ metadata:
|
|
|
354
355
|
documentation_uri: https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder
|
|
355
356
|
homepage_uri: https://govuk-form-builder.netlify.app
|
|
356
357
|
source_code_uri: https://github.com/DFE-Digital/govuk_design_system_formbuilder
|
|
358
|
+
github_repo: git@github.com:DFE-Digital/govuk_design_system_formbuilder.git
|
|
357
359
|
post_install_message:
|
|
358
360
|
rdoc_options: []
|
|
359
361
|
require_paths:
|