govuk_design_system_formbuilder 2.6.0 → 2.7.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: dd0f0c49f266a8cb411ebed4833b6284cc8cc4b6acd8ce3bf87d705feb40062b
4
- data.tar.gz: b2659204e304dd40ed2254d06f43acdd4b5b5f13fc48d180741645d004c15719
3
+ metadata.gz: '08308443752eddad69642235b4098b788ed5c5eb701b6f97d344171b9654a135'
4
+ data.tar.gz: 0f3b209aee144ea52d46798b14a29ea1a85b9acf545413d0219efeff03b92e8e
5
5
  SHA512:
6
- metadata.gz: 962d77c5cc9b3501f0b8efab08a9f7c930d3aed9b28e96e06bd4e9851fd00586eb557a43150f6b911c7ad5044d0cc4e0bc08027697faf223aa70ce0765558898
7
- data.tar.gz: 8af398e7d5673dd8b8b5f25810d88afb281a297f409c5883d567fd13a9f0347cbe644c2f32f6e69b1ec8a0e261ad81abf723e444d6186bdfb7f9901431f70c10
6
+ metadata.gz: 425224ce7905d2dd33d2123698c6f35f68e2ac640743326f811ab7b45241134f640bc054b7b75a3813edd2be558b794119437d8d4917adbe03f5cc42e38a74b9
7
+ data.tar.gz: 22d147336200ed390422201ece082289db29d6ee637aad76157195c9401fbbe52cfe6c9c9a80cd357f41543d133009a248a207547b0debaae46503503d26fe93
data/README.md CHANGED
@@ -9,7 +9,7 @@
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
10
  [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.12.0-brightgreen)](https://design-system.service.gov.uk)
11
11
  [![Rails](https://img.shields.io/badge/Ruby-2.6.7%20%E2%95%B1%202.7.3%20%E2%95%B1%203.0.1-E16D6D)](https://www.ruby-lang.org/en/downloads/)
12
- [![Ruby](https://img.shields.io/badge/Rails-6.0.3.7%20%E2%95%B1%206.1.3.2-E16D6D)](https://weblog.rubyonrails.org/releases/)
12
+ [![Ruby](https://img.shields.io/badge/Rails-6.0.4%20%E2%95%B1%206.1.3.2-E16D6D)](https://weblog.rubyonrails.org/releases/)
13
13
 
14
14
  This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
15
15
 
@@ -843,7 +843,7 @@ module GOVUKDesignSystemFormBuilder
843
843
 
844
844
  # Generates a submit button, green by default
845
845
  #
846
- # @param text [String] the button text
846
+ # @param text [String,Proc] the button text. When a +Proc+ is provided its contents will be rendered within the button element
847
847
  # @param warning [Boolean] makes the button red ({https://design-system.service.gov.uk/components/button/#warning-buttons warning}) when true
848
848
  # @param secondary [Boolean] makes the button grey ({https://design-system.service.gov.uk/components/button/#secondary-buttons secondary}) when true
849
849
  # @param classes [Array,String] Classes to add to the submit button
@@ -853,7 +853,7 @@ module GOVUKDesignSystemFormBuilder
853
853
  # client-side validation provided by the browser. This is to provide a more consistent and accessible user
854
854
  # experience
855
855
  # @param disabled [Boolean] makes the button disabled when true
856
- # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
856
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +button+ element
857
857
  # @param block [Block] When content is passed in via a block the submit element and the block content will
858
858
  # be wrapped in a +<div class="govuk-button-group">+ which will space the buttons and links within
859
859
  # evenly.
@@ -861,8 +861,9 @@ module GOVUKDesignSystemFormBuilder
861
861
  # @return [ActiveSupport::SafeBuffer] HTML output
862
862
  # @note Only the first additional button or link (passed in via a block) will be given the
863
863
  # correct left margin, subsequent buttons will need to be manually accounted for
864
- # @note This helper always renders an +<input type='submit'>+ tag, HTML content is not supported inside. You
865
- # can place +<button>+ tags inside the form to have the same effect
864
+ # @note This helper always renders an +<button type='submit'>+ tag. Previous versions of this gem rendered
865
+ # a +`<input type='submit'>' tag instead, but there is a {https://github.com/alphagov/govuk_elements/issues/545 longstanding bug}
866
+ # with this approach where the top few pixels don't initiate a submission when clicked.
866
867
  # @see https://design-system.service.gov.uk/components/button/#stop-users-from-accidentally-sending-information-more-than-once
867
868
  # GOV.UK double click prevention
868
869
  #
@@ -41,8 +41,10 @@ module GOVUKDesignSystemFormBuilder
41
41
  messages = @builder.object.errors.messages
42
42
 
43
43
  if reorder_errors?
44
- return messages.sort_by.with_index(1) do |(attr, _val), i|
45
- error_order.index(attr) || (i + messages.size)
44
+ adjustment = error_order.size + messages.size
45
+
46
+ return messages.sort_by.with_index do |(attr, _val), i|
47
+ error_order.index(attr) || (i + adjustment)
46
48
  end
47
49
  end
48
50
 
@@ -9,7 +9,7 @@ module GOVUKDesignSystemFormBuilder
9
9
 
10
10
  fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary
11
11
 
12
- @text = text
12
+ @text = build_text(text)
13
13
  @prevent_double_click = prevent_double_click
14
14
  @warning = warning
15
15
  @secondary = secondary
@@ -26,6 +26,17 @@ module GOVUKDesignSystemFormBuilder
26
26
 
27
27
  private
28
28
 
29
+ def build_text(text)
30
+ case text
31
+ when String
32
+ text
33
+ when Proc
34
+ capture { text.call }
35
+ else
36
+ fail(ArgumentError, %(text must be a String or Proc))
37
+ end
38
+ end
39
+
29
40
  def button_group
30
41
  Containers::ButtonGroup.new(@builder, buttons).html
31
42
  end
@@ -35,11 +46,12 @@ module GOVUKDesignSystemFormBuilder
35
46
  end
36
47
 
37
48
  def submit
38
- @builder.submit(@text, **attributes(@html_attributes))
49
+ @builder.tag.button(@text, **attributes(@html_attributes))
39
50
  end
40
51
 
41
52
  def options
42
53
  {
54
+ type: 'submit',
43
55
  formnovalidate: !@validate,
44
56
  disabled: @disabled,
45
57
  class: classes,
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '2.6.0'.freeze
2
+ VERSION = '2.7.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.0
4
+ version: 2.7.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-14 00:00:00.000000000 Z
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge