govuk_design_system_formbuilder 1.0.0 → 1.0.1

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: c6cd261aede14003b41cba2f6d164a952e07daf37b18ce0cdddf553391fa335e
4
- data.tar.gz: 72e545d0c8f00a97392ca6265f8ddbea7d3e28549889e9c6ec672c8560bcc503
3
+ metadata.gz: a461a934a644c5132053494bb2f7226da713744089d2d2685c2288abb203fbc6
4
+ data.tar.gz: 6015d09960437e4f7c3672738da64bc67ff7651135e0f8ce52f4e5c261ec1e27
5
5
  SHA512:
6
- metadata.gz: a040500a96d4238db0dd79dff19d27304f6463ef790a7c71b83ba88b68391a4b9c5b2285e9d839e51f34ebfed2d1dc36ac40131cfeb31567f44d0356362b6b6a
7
- data.tar.gz: 004f50ef512c190bfb96b4e1b772edf84bf73a8c33e8973542f6eca774842085889170f3dc3047df8fc21d3a76daa516ba978c2026c8cf6306ad4ec97622af84
6
+ metadata.gz: 50b788c0351f43d4919473f08cc4ba58da35a5e899fcdb1556a5ecf4edfbeb8ef327930a6a605fffee68b83d6db7cd90019ad525c86f88ce11a02eb0fd4284af
7
+ data.tar.gz: 36a30c7e31d409ef926726c0b2c56fda14c2c2606310c948810f288db2ef2a64637b9c9104d43f368e32bb5ebff4a38719a8e38a9fd76367f97e762d96b92fb7
@@ -68,6 +68,14 @@ module GOVUKDesignSystemFormBuilder
68
68
  build_id('supplemental')
69
69
  end
70
70
 
71
+ # Provides an id for use by the textual description of character and word limits.
72
+ #
73
+ # @note In order for the GOV.UK Frontend JavaScript to pick up this associated field
74
+ # it has to have the same id as the text area with the additional suffix of '-info'
75
+ def limit_id
76
+ [field_id(link_errors: true), 'info'].join('-')
77
+ end
78
+
71
79
  def has_errors?
72
80
  @builder.object.errors.any? &&
73
81
  @builder.object.errors.messages.dig(@attribute_name).present?
@@ -23,14 +23,11 @@ module GOVUKDesignSystemFormBuilder
23
23
  id: field_id(link_errors: true),
24
24
  class: govuk_textarea_classes,
25
25
  aria: {
26
- describedby: described_by(
27
- hint_id,
28
- error_id,
29
- supplemental_id
30
- )
26
+ describedby: described_by(hint_id, error_id, supplemental_id, limit_description_id)
31
27
  },
32
28
  **@extra_args.merge(rows: @rows)
33
- )
29
+ ),
30
+ limit_description
34
31
  ].flatten.compact
35
32
  )
36
33
  end
@@ -49,6 +46,28 @@ module GOVUKDesignSystemFormBuilder
49
46
  def limit?
50
47
  @max_words || @max_chars
51
48
  end
49
+
50
+ def limit_description
51
+ return nil unless limit?
52
+
53
+ content_tag('span', id: limit_id, class: %w(govuk-hint govuk-character-count__message), aria: { live: 'polite' }) do
54
+ "You can enter up to #{limit_quantity} #{limit_type}"
55
+ end
56
+ end
57
+
58
+ def limit_quantity
59
+ @max_words || @max_chars
60
+ end
61
+
62
+ def limit_type
63
+ @max_words.present? ? 'words' : 'characters'
64
+ end
65
+
66
+ def limit_description_id
67
+ return nil unless limit?
68
+
69
+ limit_id
70
+ end
52
71
  end
53
72
  end
54
73
  end
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-19 00:00:00.000000000 Z
11
+ date: 2019-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview