govuk_design_system_formbuilder 2.1.4 → 2.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b243fcaf512a7b1edd2455a06cb36368db533c9aa76661fc907d8725a916ecc
4
- data.tar.gz: 2ac392952f097e0730dc1d10b4b159d273a17335682ddcf8c8a5d589c7d0e53f
3
+ metadata.gz: b3150318cc7e6d0cd73188a05884f0b321b7facd3523d4d4458cc70efee5f396
4
+ data.tar.gz: feabd9a11432921e52ef3fc9c948e154106b18105d61ff512c391951f4e21cbd
5
5
  SHA512:
6
- metadata.gz: b4ff3afdcc29348497365e6e04f4a2848c9db92e57fe6db4098a011d5cefd00e3f0a6e38240e7eb4b5776b79a29f36f64785bbfdeb0181b9efed8d5c46813359
7
- data.tar.gz: 28c9f927dbfbe0b7176184ececf28c6de7ad229613728f7e57d5aed9d5f93c2d49d2d81ff474bad47a809a85dd847a4658d0af9695cdfa5a10a9705272ed926c
6
+ metadata.gz: 18b17fbcd9cd16c57c5a42fc580595773a9a06835c768e7330245f006268e2b3999a520cbe39279e59bd84086eeea165018df4689e287212354352b21641a9c0
7
+ data.tar.gz: 36fb4d615b1fb988f5a248a310ea8be52310125330df52c0a843e96f95ecbf209f30de2c0ad7489d64581140920fd8c0f2a29430cc534d8f5d9700ae8a1211a4
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # GOV.UK Design System Form Builder for Rails
2
2
 
3
- [![Build Status](https://travis-ci.com/DFE-Digital/govuk_design_system_formbuilder.svg?branch=master)](https://travis-ci.com/DFE-Digital/govuk_design_system_formbuilder)
3
+ [![Tests](https://github.com/DFE-Digital/govuk_design_system_formbuilder/workflows/Tests/badge.svg)](https://github.com/DFE-Digital/govuk_design_system_formbuilder/actions)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/fde73b5dc9476197281b/maintainability)](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/maintainability)
5
5
  [![Gem Version](https://badge.fury.io/rb/govuk_design_system_formbuilder.svg)](https://badge.fury.io/rb/govuk_design_system_formbuilder)
6
6
  [![Gem](https://img.shields.io/gem/dt/govuk_design_system_formbuilder?logo=rubygems)](https://rubygems.org/gems/govuk_design_system_formbuilder)
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.9.1-brightgreen)](https://design-system.service.gov.uk)
10
+ [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.10.2-brightgreen)](https://design-system.service.gov.uk)
11
+ [![Rails](https://img.shields.io/badge/Ruby-2.5.8%20%E2%95%B1%202.6.6%20%E2%95%B1%202.7.2-E16D6D)](https://weblog.rubyonrails.org/releases/)
12
+ [![Ruby](https://img.shields.io/badge/Rails-5.2.4%20%E2%95%B1%206.0.3%20%E2%95%B1%206.1.0-E16D6D)](https://www.ruby-lang.org/en/downloads/)
11
13
 
12
14
  This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
13
15
 
@@ -53,7 +53,7 @@ module GOVUKDesignSystemFormBuilder
53
53
  def has_errors?
54
54
  @builder.object.respond_to?(:errors) &&
55
55
  @builder.object.errors.any? &&
56
- @builder.object.errors.messages.dig(@attribute_name).present?
56
+ @builder.object.errors.messages[@attribute_name].present?
57
57
  end
58
58
 
59
59
  def described_by(*ids)
@@ -456,6 +456,7 @@ module GOVUKDesignSystemFormBuilder
456
456
  # @param inline [Boolean] controls whether the radio buttons are displayed inline or not
457
457
  # @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
458
458
  # @param bold_labels [Boolean] controls whether the radio button labels are bold
459
+ # @param include_hidden [Boolean] controls whether a hidden field is inserted to allow for empty submissions
459
460
  # @param classes [Array,String] Classes to add to the radio button container.
460
461
  # @option legend text [String] the fieldset legend's text content
461
462
  # @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
@@ -500,7 +501,7 @@ module GOVUKDesignSystemFormBuilder
500
501
  # :name,
501
502
  # legend: -> { tag.h3('Which category do you belong to?') }
502
503
  #
503
- 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: false, classes: nil, form_group: {}, &block)
504
+ 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: false, classes: nil, include_hidden: false, form_group: {}, &block)
504
505
  Elements::Radios::Collection.new(
505
506
  self,
506
507
  object_name,
@@ -517,6 +518,7 @@ module GOVUKDesignSystemFormBuilder
517
518
  bold_labels: bold_labels,
518
519
  classes: classes,
519
520
  form_group: form_group,
521
+ include_hidden: include_hidden,
520
522
  &block
521
523
  ).html
522
524
  end
@@ -850,6 +852,7 @@ module GOVUKDesignSystemFormBuilder
850
852
  # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
851
853
  # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
852
854
  # @param omit_day [Boolean] do not render a day input, only capture month and year
855
+ # @param wildcards [Boolean] add an 'X' to the day and month patterns so users can add approximate dates
853
856
  # @param form_group [Hash] configures the form group
854
857
  # @option form_group classes [Array,String] sets the form group's classes
855
858
  # @option form_group kwargs [Hash] additional attributes added to the form group
@@ -872,8 +875,8 @@ module GOVUKDesignSystemFormBuilder
872
875
  # @example A date input with legend supplied as a proc
873
876
  # = f.govuk_date_field :finishes_on,
874
877
  # legend: -> { tag.h3('Which category do you belong to?') }
875
- def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, &block)
876
- Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group: form_group, &block).html
878
+ def govuk_date_field(attribute_name, hint: {}, legend: {}, caption: {}, date_of_birth: false, omit_day: false, form_group: {}, wildcards: false, &block)
879
+ Elements::Date.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, date_of_birth: date_of_birth, omit_day: omit_day, form_group: form_group, wildcards: wildcards, &block).html
877
880
  end
878
881
 
879
882
  # Generates a summary of errors in the form, each linking to the corresponding
@@ -2,7 +2,7 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class CharacterCount < Base
4
4
  def initialize(builder, max_words:, max_chars:, threshold:)
5
- @builder = builder
5
+ super(builder, nil, nil)
6
6
 
7
7
  fail ArgumentError, 'limit can be words or chars' if max_words && max_chars
8
8
 
@@ -11,10 +11,10 @@ module GOVUKDesignSystemFormBuilder
11
11
  @threshold = threshold
12
12
  end
13
13
 
14
- def html
14
+ def html(&block)
15
15
  return yield unless limit?
16
16
 
17
- tag.div(**options) { yield }
17
+ tag.div(**options, &block)
18
18
  end
19
19
 
20
20
  private
@@ -2,13 +2,14 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class CheckBoxes < Base
4
4
  def initialize(builder, small:, classes: nil)
5
- @builder = builder
5
+ super(builder, nil, nil)
6
+
6
7
  @small = small
7
8
  @classes = classes
8
9
  end
9
10
 
10
- def html
11
- tag.div(**options) { yield }
11
+ def html(&block)
12
+ tag.div(**options, &block)
12
13
  end
13
14
 
14
15
  private
@@ -8,8 +8,8 @@ module GOVUKDesignSystemFormBuilder
8
8
  @html_attributes = kwargs
9
9
  end
10
10
 
11
- def html
12
- tag.div(class: classes, **@html_attributes) { yield }
11
+ def html(&block)
12
+ tag.div(class: classes, **@html_attributes, &block)
13
13
  end
14
14
 
15
15
  private
@@ -4,14 +4,15 @@ module GOVUKDesignSystemFormBuilder
4
4
  include Traits::Hint
5
5
 
6
6
  def initialize(builder, inline:, small:, classes:)
7
- @builder = builder
7
+ super(builder, nil, nil)
8
+
8
9
  @inline = inline
9
10
  @small = small
10
11
  @classes = classes
11
12
  end
12
13
 
13
- def html
14
- tag.div(**options) { yield }
14
+ def html(&block)
15
+ tag.div(**options, &block)
15
16
  end
16
17
 
17
18
  private
@@ -6,7 +6,7 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Hint
7
7
  include Traits::Supplemental
8
8
 
9
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method: nil, hint:, legend:, caption:, small:, classes:, form_group:, &block)
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, legend:, caption:, small:, classes:, form_group:, hint_method: nil, &block)
10
10
  super(builder, object_name, attribute_name, &block)
11
11
 
12
12
  @collection = collection
@@ -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
- [localised_text(:label), @checkbox.text, @value].compact.first
19
+ [localised_text(:label), @checkbox.text, @value].compact.first.to_s
20
20
  end
21
21
  end
22
22
 
@@ -9,7 +9,7 @@ module GOVUKDesignSystemFormBuilder
9
9
 
10
10
  SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
11
11
 
12
- def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, date_of_birth: false, omit_day:, form_group:, &block)
12
+ def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, omit_day:, form_group:, wildcards:, date_of_birth: false, &block)
13
13
  super(builder, object_name, attribute_name, &block)
14
14
 
15
15
  @legend = legend
@@ -18,6 +18,7 @@ module GOVUKDesignSystemFormBuilder
18
18
  @date_of_birth = date_of_birth
19
19
  @omit_day = omit_day
20
20
  @form_group = form_group
21
+ @wildcards = wildcards
21
22
  end
22
23
 
23
24
  def html
@@ -82,13 +83,19 @@ module GOVUKDesignSystemFormBuilder
82
83
  class: classes(width),
83
84
  name: name(segment),
84
85
  type: 'text',
85
- pattern: '[0-9]*',
86
+ pattern: pattern(segment),
86
87
  inputmode: 'numeric',
87
88
  value: value,
88
89
  autocomplete: date_of_birth_autocomplete_value(segment)
89
90
  )
90
91
  end
91
92
 
93
+ def pattern(segment)
94
+ return '[0-9X]*' if @wildcards && segment.in?(%i(day month))
95
+
96
+ '[0-9]*'
97
+ end
98
+
92
99
  def classes(width)
93
100
  %w(input date-input__input).prefix(brand).tap do |classes|
94
101
  classes.push(%(#{brand}-input--width-#{width}))
@@ -5,10 +5,6 @@ module GOVUKDesignSystemFormBuilder
5
5
 
6
6
  include Traits::Error
7
7
 
8
- def initialize(builder, object_name, attribute_name)
9
- super(builder, object_name, attribute_name)
10
- end
11
-
12
8
  def html
13
9
  return nil unless has_errors?
14
10
 
@@ -4,8 +4,8 @@ module GOVUKDesignSystemFormBuilder
4
4
  include Traits::Error
5
5
 
6
6
  def initialize(builder, object_name, title, link_base_errors_to:)
7
- @builder = builder
8
- @object_name = object_name
7
+ super(builder, object_name, nil)
8
+
9
9
  @title = title
10
10
  @link_base_errors_to = link_base_errors_to
11
11
  end
@@ -1,7 +1,9 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Null < Base
4
- def initialize; end
4
+ def initialize
5
+ super(nil, nil, nil)
6
+ end
5
7
 
6
8
  def html
7
9
  nil
@@ -6,27 +6,28 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Hint
7
7
  include Traits::Supplemental
8
8
 
9
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint:, legend:, caption:, inline:, small:, bold_labels:, classes:, form_group:, &block)
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint:, legend:, caption:, inline:, small:, bold_labels:, classes:, form_group:, include_hidden:, &block)
10
10
  super(builder, object_name, attribute_name, &block)
11
11
 
12
- @collection = collection
13
- @value_method = value_method
14
- @text_method = text_method
15
- @hint_method = hint_method
16
- @inline = inline
17
- @small = small
18
- @legend = legend
19
- @caption = caption
20
- @hint = hint
21
- @classes = classes
22
- @form_group = form_group
23
- @bold_labels = hint_method.present? || bold_labels
12
+ @collection = collection
13
+ @value_method = value_method
14
+ @text_method = text_method
15
+ @hint_method = hint_method
16
+ @inline = inline
17
+ @small = small
18
+ @legend = legend
19
+ @caption = caption
20
+ @hint = hint
21
+ @classes = classes
22
+ @form_group = form_group
23
+ @include_hidden = include_hidden
24
+ @bold_labels = hint_method.present? || bold_labels
24
25
  end
25
26
 
26
27
  def html
27
28
  Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
28
29
  Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
29
- safe_join([supplemental_content, hint_element, error_element, radios])
30
+ safe_join([hidden_field, supplemental_content, hint_element, error_element, radios])
30
31
  end
31
32
  end
32
33
  end
@@ -47,6 +48,12 @@ module GOVUKDesignSystemFormBuilder
47
48
  end
48
49
  end
49
50
 
51
+ def hidden_field
52
+ return unless @include_hidden
53
+
54
+ @builder.hidden_field(@attribute_name, value: "")
55
+ end
56
+
50
57
  def collection
51
58
  @collection.map.with_index do |item, i|
52
59
  Elements::Radios::CollectionRadioButton.new(@builder, @object_name, @attribute_name, item, **collection_options(i)).html
@@ -6,7 +6,7 @@ module GOVUKDesignSystemFormBuilder
6
6
  include Traits::Hint
7
7
  include Traits::Supplemental
8
8
 
9
- def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, options: {}, html_options: {}, hint:, label:, caption:, form_group:, &block)
9
+ def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, label:, caption:, form_group:, options: {}, html_options: {}, &block)
10
10
  super(builder, object_name, attribute_name, &block)
11
11
 
12
12
  @collection = collection
@@ -49,7 +49,7 @@ module GOVUKDesignSystemFormBuilder
49
49
  end
50
50
 
51
51
  def custom_classes
52
- @html_options.dig(:class)
52
+ @html_options[:class]
53
53
  end
54
54
  end
55
55
  end
@@ -4,9 +4,10 @@ module GOVUKDesignSystemFormBuilder
4
4
  using PrefixableArray
5
5
 
6
6
  def initialize(builder, text, warning:, secondary:, classes:, prevent_double_click:, validate:, disabled:, &block)
7
+ super(builder, nil, nil)
8
+
7
9
  fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary
8
10
 
9
- @builder = builder
10
11
  @text = text
11
12
  @prevent_double_click = prevent_double_click
12
13
  @warning = warning
@@ -8,7 +8,7 @@ module GOVUKDesignSystemFormBuilder
8
8
  when Symbol, String
9
9
  item.send(method)
10
10
  when Proc
11
- capture { method.call(item) }
11
+ capture { method.call(item).to_s }
12
12
  end
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '2.1.4'.freeze
2
+ VERSION = '2.1.7'.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.1.4
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-07 00:00:00.000000000 Z
11
+ date: 2021-01-27 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.17.1
137
+ version: '0.20'
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.17.1
144
+ version: '0.20'
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.24.0
179
+ version: 3.26.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.24.0
186
+ version: 3.26.0
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: rubypants
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -305,7 +305,7 @@ metadata:
305
305
  documentation_uri: https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder
306
306
  homepage_uri: https://govuk-form-builder.netlify.app
307
307
  source_code_uri: https://github.com/DFE-Digital/govuk_design_system_formbuilder
308
- post_install_message:
308
+ post_install_message:
309
309
  rdoc_options: []
310
310
  require_paths:
311
311
  - lib
@@ -320,8 +320,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
320
320
  - !ruby/object:Gem::Version
321
321
  version: '0'
322
322
  requirements: []
323
- rubygems_version: 3.1.2
324
- signing_key:
323
+ rubygems_version: 3.1.4
324
+ signing_key:
325
325
  specification_version: 4
326
326
  summary: GOV.UK-compliant Rails form builder
327
327
  test_files: []