govuk_design_system_formbuilder 2.6.0b1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/govuk_design_system_formbuilder.rb +5 -0
- data/lib/govuk_design_system_formbuilder/builder.rb +6 -2
- data/lib/govuk_design_system_formbuilder/builder_helper.rb +2 -2
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +36 -9
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd0f0c49f266a8cb411ebed4833b6284cc8cc4b6acd8ce3bf87d705feb40062b
|
4
|
+
data.tar.gz: b2659204e304dd40ed2254d06f43acdd4b5b5f13fc48d180741645d004c15719
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962d77c5cc9b3501f0b8efab08a9f7c930d3aed9b28e96e06bd4e9851fd00586eb557a43150f6b911c7ad5044d0cc4e0bc08027697faf223aa70ce0765558898
|
7
|
+
data.tar.gz: 8af398e7d5673dd8b8b5f25810d88afb281a297f409c5883d567fd13a9f0347cbe644c2f32f6e69b1ec8a0e261ad81abf723e444d6186bdfb7f9901431f70c10
|
@@ -41,6 +41,10 @@ module GOVUKDesignSystemFormBuilder
|
|
41
41
|
# * +:default_collection_radio_buttons_include_hidden+ controls whether or not
|
42
42
|
# a hidden field is added when rendering a collection of radio buttons
|
43
43
|
#
|
44
|
+
# * +:default_error_summary_error_order_method+ is the method that the library
|
45
|
+
# will check for on the bound object to see whether or not to try ordering the
|
46
|
+
# error messages
|
47
|
+
#
|
44
48
|
# * +:localisation_schema_fallback+ sets the prefix elements for the array
|
45
49
|
# used to build the localisation string. The final two elements are always
|
46
50
|
# are the object name and attribute name. The _special_ value +__context__+,
|
@@ -62,6 +66,7 @@ module GOVUKDesignSystemFormBuilder
|
|
62
66
|
default_submit_button_text: 'Continue',
|
63
67
|
default_radio_divider_text: 'or',
|
64
68
|
default_error_summary_title: 'There is a problem',
|
69
|
+
default_error_summary_error_order_method: nil,
|
65
70
|
default_collection_check_boxes_include_hidden: true,
|
66
71
|
default_collection_radio_buttons_include_hidden: true,
|
67
72
|
default_submit_validate: false,
|
@@ -930,7 +930,11 @@ module GOVUKDesignSystemFormBuilder
|
|
930
930
|
# @param title [String] the error summary heading
|
931
931
|
# @param link_base_errors_to [Symbol,String] set the field that errors on +:base+ are linked
|
932
932
|
# to, as there won't be a field representing the object base.
|
933
|
+
# @param order [Array<Symbol>] the attribute order in which error messages are displayed. Ordered
|
934
|
+
# attributes will appear first and unordered ones will be last, sorted in the default manner (in
|
935
|
+
# which they were defined on the model).
|
933
936
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the error summary +div+ element
|
937
|
+
# @param block [Block] arbitrary HTML that will be rendered between title and error message list
|
934
938
|
#
|
935
939
|
# @note Only the first error in the +#errors+ array for each attribute will
|
936
940
|
# be included.
|
@@ -939,8 +943,8 @@ module GOVUKDesignSystemFormBuilder
|
|
939
943
|
# = f.govuk_error_summary 'Uh-oh, spaghettios'
|
940
944
|
#
|
941
945
|
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
|
942
|
-
def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil, **kwargs)
|
943
|
-
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, **kwargs).html
|
946
|
+
def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil, order: nil, **kwargs, &block)
|
947
|
+
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to, order: order, **kwargs, &block).html
|
944
948
|
end
|
945
949
|
|
946
950
|
# Generates a fieldset containing the contents of the block
|
@@ -42,10 +42,10 @@ module GOVUKDesignSystemFormBuilder
|
|
42
42
|
# = govuk_error_summary(@registration)
|
43
43
|
#
|
44
44
|
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
|
45
|
-
def govuk_error_summary(object, object_name = nil, *args, **kwargs)
|
45
|
+
def govuk_error_summary(object, object_name = nil, *args, **kwargs, &block)
|
46
46
|
(object_name = retrieve_object_name(object)) if object_name.nil?
|
47
47
|
|
48
|
-
proxy_builder(object, object_name, self, {}).govuk_error_summary(*args, **kwargs)
|
48
|
+
proxy_builder(object, object_name, self, {}).govuk_error_summary(*args, **kwargs, &block)
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
@@ -4,12 +4,13 @@ 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:, **kwargs)
|
8
|
-
super(builder, object_name, nil)
|
7
|
+
def initialize(builder, object_name, title, link_base_errors_to:, order:, **kwargs, &block)
|
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
|
+
@order = order
|
13
14
|
end
|
14
15
|
|
15
16
|
def html
|
@@ -27,17 +28,43 @@ module GOVUKDesignSystemFormBuilder
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def summary
|
30
|
-
tag.div(class: summary_class('body'))
|
31
|
-
tag.ul(class: [%(#{brand}-list), summary_class('list')]) do
|
32
|
-
safe_join(list)
|
33
|
-
end
|
34
|
-
end
|
31
|
+
tag.div(class: summary_class('body')) { safe_join([@block_content, list]) }
|
35
32
|
end
|
36
33
|
|
37
34
|
def list
|
38
|
-
|
39
|
-
list_item(attribute, messages.first)
|
35
|
+
tag.ul(class: [%(#{brand}-list), summary_class('list')]) do
|
36
|
+
safe_join(error_messages.map { |attribute, messages| list_item(attribute, messages.first) })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def error_messages
|
41
|
+
messages = @builder.object.errors.messages
|
42
|
+
|
43
|
+
if reorder_errors?
|
44
|
+
return messages.sort_by.with_index(1) do |(attr, _val), i|
|
45
|
+
error_order.index(attr) || (i + messages.size)
|
46
|
+
end
|
40
47
|
end
|
48
|
+
|
49
|
+
@builder.object.errors.messages
|
50
|
+
end
|
51
|
+
|
52
|
+
def reorder_errors?
|
53
|
+
object = @builder.object
|
54
|
+
|
55
|
+
@order || (error_order_method &&
|
56
|
+
object.respond_to?(error_order_method) &&
|
57
|
+
object.send(error_order_method).present?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def error_order
|
61
|
+
@order || @builder.object.send(config.default_error_summary_error_order_method)
|
62
|
+
end
|
63
|
+
|
64
|
+
# this method will be called on the bound object to see if custom error ordering
|
65
|
+
# has been enabled
|
66
|
+
def error_order_method
|
67
|
+
config.default_error_summary_error_order_method
|
41
68
|
end
|
42
69
|
|
43
70
|
def list_item(attribute, message)
|
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.6.
|
4
|
+
version: 2.6.0
|
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-06-
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep_merge
|
@@ -365,9 +365,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
365
365
|
version: '0'
|
366
366
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
367
367
|
requirements:
|
368
|
-
- - "
|
368
|
+
- - ">="
|
369
369
|
- !ruby/object:Gem::Version
|
370
|
-
version:
|
370
|
+
version: '0'
|
371
371
|
requirements: []
|
372
372
|
rubygems_version: 3.1.6
|
373
373
|
signing_key:
|