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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 434236656800572e0d71e47fe88ae20e5f50c6822f3cf344204f08a934032cb9
4
- data.tar.gz: 4746012c475f169cf556fed6512ef89aa0187e95f351addc38b14da835db6137
3
+ metadata.gz: dd0f0c49f266a8cb411ebed4833b6284cc8cc4b6acd8ce3bf87d705feb40062b
4
+ data.tar.gz: b2659204e304dd40ed2254d06f43acdd4b5b5f13fc48d180741645d004c15719
5
5
  SHA512:
6
- metadata.gz: 6dae8d1bc5dec93e9088aa68f78df41fd06bd9a9815ee65919b14c7fcb96aeb27400390f83e122e540392b2254378c03d2e7455316f9e09d3c4694652e801ce1
7
- data.tar.gz: 3f3a3a53125291c4822e2b557c3c6f0ed053e4127bf0b7561b5bc82ca5a1a14b601d01b591bf4dd6901979f3b0b55a018c52ecf74e769ef602ddaef05ea454d4
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')) do
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
- @builder.object.errors.messages.map do |attribute, messages|
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)
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '2.6.0b1'.freeze
2
+ VERSION = '2.6.0'.freeze
3
3
  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.6.0b1
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-09 00:00:00.000000000 Z
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: 1.3.1
370
+ version: '0'
371
371
  requirements: []
372
372
  rubygems_version: 3.1.6
373
373
  signing_key: