crown_marketplace_utils 0.1.0.beta.6 → 0.1.0.beta.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/accordion.rb +91 -89
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/back_link.rb +24 -22
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/breadcrumbs.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/button.rb +109 -107
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/details.rb +33 -31
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/error_message.rb +49 -47
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/character_count.rb +144 -142
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/checkboxes.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/date_input.rb +126 -124
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/file_upload.rb +75 -73
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/input.rb +137 -135
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/radios.rb +176 -174
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/select.rb +111 -109
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field/textarea.rb +86 -84
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/field.rb +181 -179
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/fieldset.rb +56 -54
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/form_group.rb +37 -35
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/header.rb +142 -140
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/hint.rb +25 -23
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/label.rb +69 -67
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/notification_banner.rb +121 -119
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/pagination.rb +290 -288
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/step_by_step_navigation.rb +187 -185
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/tag.rb +29 -27
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper/warning_text.rb +39 -37
- data/lib/crown_marketplace_utils/helpers/gov_uk_helper.rb +31 -29
- data/lib/crown_marketplace_utils/version.rb +1 -1
- metadata +1 -1
@@ -2,102 +2,104 @@
|
|
2
2
|
|
3
3
|
require_relative '../field'
|
4
4
|
|
5
|
-
module CrownMarketplaceUtils
|
6
|
-
module
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
# This helper is used for generating the textarea component from the
|
11
|
-
# {https://design-system.service.gov.uk/components/textarea GDS - Components - Textarea}
|
12
|
-
#
|
13
|
-
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
14
|
-
|
15
|
-
module Textarea
|
16
|
-
include Field
|
17
|
-
|
18
|
-
# Generates the HTML for the GOV.UK textarea component
|
19
|
-
#
|
20
|
-
# @param attribute [String, Symbol] the attribute of the textarea
|
21
|
-
# @param govuk_textarea_options [Hash] options that will be used for the parts of the form group, label, hint and textarea
|
5
|
+
module CrownMarketplaceUtils
|
6
|
+
module Helpers
|
7
|
+
module GovUkHelper
|
8
|
+
module Field
|
9
|
+
# = GOV.UK Textarea
|
22
10
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# @option govuk_textarea_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
26
|
-
# the textarea tag and find the error message
|
27
|
-
# @option govuk_textarea_options [Hash] :form_group see {govuk_field}
|
28
|
-
# @option govuk_textarea_options [Hash] :label see {govuk_field}
|
29
|
-
# @option govuk_textarea_options [Hash] :hint see {govuk_field}
|
30
|
-
# @option govuk_textarea_options [Hash] :textarea ({}) the options that will be used when rendering the textarea.
|
31
|
-
# See {set_govuk_textarea_field_options} for more details.
|
11
|
+
# This helper is used for generating the textarea component from the
|
12
|
+
# {https://design-system.service.gov.uk/components/textarea GDS - Components - Textarea}
|
32
13
|
#
|
33
|
-
#
|
34
|
-
# which can then be rendered on the page
|
14
|
+
# This is considered a Field module and so makes use of the methods in {CrownMarketplaceUtils::GovUkHelper::Field}
|
35
15
|
|
36
|
-
|
37
|
-
|
38
|
-
set_govuk_textarea_field_options(error_message, govuk_field_options)
|
39
|
-
(govuk_textarea_options[:textarea] ||= {})[:content] = govuk_textarea_options[:model].send(attribute) if govuk_textarea_options[:model]
|
16
|
+
module Textarea
|
17
|
+
include Field
|
40
18
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
19
|
+
# Generates the HTML for the GOV.UK textarea component
|
20
|
+
#
|
21
|
+
# @param attribute [String, Symbol] the attribute of the textarea
|
22
|
+
# @param govuk_textarea_options [Hash] options that will be used for the parts of the form group, label, hint and textarea
|
23
|
+
#
|
24
|
+
# @option govuk_textarea_options [String] :error_message (nil) the error message to be displayed
|
25
|
+
# @option govuk_textarea_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
26
|
+
# @option govuk_textarea_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
27
|
+
# the textarea tag and find the error message
|
28
|
+
# @option govuk_textarea_options [Hash] :form_group see {govuk_field}
|
29
|
+
# @option govuk_textarea_options [Hash] :label see {govuk_field}
|
30
|
+
# @option govuk_textarea_options [Hash] :hint see {govuk_field}
|
31
|
+
# @option govuk_textarea_options [Hash] :textarea ({}) the options that will be used when rendering the textarea.
|
32
|
+
# See {set_govuk_textarea_field_options} for more details.
|
33
|
+
#
|
34
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK textarea
|
35
|
+
# which can then be rendered on the page
|
36
|
+
|
37
|
+
def govuk_textarea(attribute, **govuk_textarea_options)
|
38
|
+
govuk_field(:textarea, attribute, **govuk_textarea_options) do |govuk_field_options, error_message|
|
39
|
+
set_govuk_textarea_field_options(error_message, govuk_field_options)
|
40
|
+
(govuk_textarea_options[:textarea] ||= {})[:content] = govuk_textarea_options[:model].send(attribute) if govuk_textarea_options[:model]
|
41
|
+
|
42
|
+
concat(
|
43
|
+
if govuk_textarea_options[:form]
|
44
|
+
govuk_textarea_form(govuk_textarea_options[:form], attribute, **govuk_field_options)
|
45
|
+
else
|
46
|
+
govuk_textarea_tag(attribute, **govuk_field_options)
|
47
|
+
end
|
48
|
+
)
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
+
private
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
# Generates the textarea HTML for {govuk_textarea}
|
55
|
+
#
|
56
|
+
# @param attribute [String, Symbol] the attribute of the textarea
|
57
|
+
# @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
|
58
|
+
#
|
59
|
+
# @option (see set_govuk_textarea_field_options)
|
60
|
+
#
|
61
|
+
# @return [ActiveSupport::SafeBuffer] the HTML for the textarea field which is used in {govuk_textarea}
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
def govuk_textarea_tag(attribute, **govuk_text_textarea_options)
|
64
|
+
text_area_tag(
|
65
|
+
attribute,
|
66
|
+
govuk_text_textarea_options[:content],
|
67
|
+
**govuk_text_textarea_options[:attributes]
|
68
|
+
)
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
# Generates the textarea HTML for {govuk_textarea} when there is a ActionView::Helpers::FormBuilder
|
72
|
+
#
|
73
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the textarea
|
74
|
+
# @param (see govuk_textarea_tag)
|
75
|
+
#
|
76
|
+
# @option (see set_govuk_textarea_field_options)
|
77
|
+
#
|
78
|
+
# @return (see govuk_textarea_tag)
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
def govuk_textarea_form(form, attribute, **govuk_text_textarea_options)
|
81
|
+
form.text_area(
|
82
|
+
attribute,
|
83
|
+
**govuk_text_textarea_options[:attributes]
|
84
|
+
)
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
87
|
+
# Initialises the attributes for the textarea input
|
88
|
+
#
|
89
|
+
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
90
|
+
# @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
|
91
|
+
#
|
92
|
+
# @option govuk_text_textarea_options [String] :classes additional CSS classes for the textarea HTML
|
93
|
+
# @option govuk_text_textarea_options [String] :content (nil) the content of the textarea
|
94
|
+
# @option govuk_text_textarea_options [String] :rows (5) the number of rows for the text area
|
95
|
+
# @option govuk_text_textarea_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
def set_govuk_textarea_field_options(error_message, govuk_text_textarea_options)
|
98
|
+
govuk_text_textarea_options[:attributes] ||= {}
|
99
|
+
govuk_text_textarea_options[:attributes][:class] = "govuk-textarea #{govuk_text_textarea_options[:classes]}".rstrip
|
100
|
+
govuk_text_textarea_options[:attributes][:class] << ' govuk-textarea--error' if error_message
|
101
|
+
govuk_text_textarea_options[:attributes][:rows] ||= govuk_text_textarea_options[:rows] || 5
|
102
|
+
end
|
101
103
|
end
|
102
104
|
end
|
103
105
|
end
|
@@ -5,211 +5,213 @@ require_relative 'form_group'
|
|
5
5
|
require_relative 'hint'
|
6
6
|
require_relative 'label'
|
7
7
|
|
8
|
-
module CrownMarketplaceUtils
|
9
|
-
module
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
8
|
+
module CrownMarketplaceUtils
|
9
|
+
module Helpers
|
10
|
+
module GovUkHelper
|
11
|
+
# = GOV.UK Field
|
12
|
+
#
|
13
|
+
# This module contains methods to wrap the:
|
14
|
+
# - fieldset
|
15
|
+
# - form group
|
16
|
+
# - label
|
17
|
+
# - hint
|
18
|
+
# - error message
|
19
|
+
# around some kind of input.
|
20
|
+
#
|
21
|
+
# The wrapper functions in this module are used
|
22
|
+
# to create the fields using the structure of a GDS input field component.
|
23
|
+
|
24
|
+
module Field
|
25
|
+
include Fieldset
|
26
|
+
include FormGroup
|
27
|
+
include Hint
|
28
|
+
include Label
|
29
|
+
|
30
|
+
# Generates the HTML to wrap arround a GDS input field component.
|
31
|
+
#
|
32
|
+
# @param field [Symbol] the type of the field
|
33
|
+
# @param attribute [String, Symbol] the attribute of the field
|
34
|
+
# @param govuk_field_options [Hash] options that will be used for the parts of the form group, label, hint and field
|
35
|
+
#
|
36
|
+
# @option govuk_field_options [String] :error_message (nil) the error message to be displayed
|
37
|
+
# @option govuk_field_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
38
|
+
# @option govuk_field_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
39
|
+
# the field and find the error message
|
40
|
+
# @option govuk_field_options [Hash] :form_group ({}) the options for govuk_form_group {govuk_form_group}
|
41
|
+
# @option govuk_field_options [Hash] :label the parameters that will be used to create the label for the field, see {govuk_label}
|
42
|
+
# @option govuk_field_options [Hash] :hint (nil) the parameters that will be used to create the hint for the field, see {govuk_hint}.
|
43
|
+
# If no hint is given then no hint will be rendered
|
44
|
+
# @option govuk_field_options [Hash] :field_options ({}) the options that will be used when rendering the field.
|
45
|
+
# For more details look at the specific module that uses +Field+.
|
46
|
+
#
|
47
|
+
# @yield the field HTML
|
48
|
+
#
|
49
|
+
# @yieldparam govuk_field_options [Hash] the HTML options used when rendering the field
|
50
|
+
# @yieldparam error_message [String] flag to indicate if there are any erros
|
51
|
+
#
|
52
|
+
# @return [ActiveSupport::SafeBuffer] the HTML that wraps arround the field
|
53
|
+
|
54
|
+
def govuk_field(field, attribute, **govuk_field_options)
|
55
|
+
set_label_for_if_custom_id(field, govuk_field_options)
|
56
|
+
set_hint_id(attribute, govuk_field_options)
|
57
|
+
error_message = find_field_error_message(attribute, govuk_field_options)
|
58
|
+
|
59
|
+
govuk_form_group(attribute, error_message: error_message, **(govuk_field_options[:form_group] || {})) do |display_error_message|
|
60
|
+
set_field_described_by(field, attribute, error_message, govuk_field_options)
|
61
|
+
|
62
|
+
capture do
|
63
|
+
concat(govuk_label(attribute, govuk_field_options[:label][:text], form: govuk_field_options[:form], **govuk_field_options[:label]))
|
64
|
+
concat(govuk_hint(govuk_field_options[:hint][:text], **govuk_field_options[:hint])) if govuk_field_options[:hint]
|
65
|
+
concat(display_error_message)
|
66
|
+
yield(govuk_field_options[field], error_message)
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
68
|
-
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
71
|
+
# Generates the HTML to wrap arround a GDS input fields component.
|
72
|
+
# These are inputs that require being wrapped in a fieldset, for example radio buttons.
|
73
|
+
#
|
74
|
+
# @param field [Symbol] the type of the fields
|
75
|
+
# @param attribute [String, Symbol] the attribute of the fields
|
76
|
+
# @param govuk_fields_options [Hash] options that will be used for the parts of the fieldset, form group, hint and fields
|
77
|
+
#
|
78
|
+
# @option govuk_fields_options [String] :error_message (nil) the error message to be displayed
|
79
|
+
# @option govuk_fields_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
80
|
+
# @option govuk_fields_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
81
|
+
# the field and find the error message
|
82
|
+
# @option govuk_fields_options [Hash] :form_group ({}) the options for govuk_form_group {govuk_form_group}
|
83
|
+
# @option govuk_fields_options [Hash] :fieldset ({}) the options for govuk_fieldset {govuk_fieldset}
|
84
|
+
# @option govuk_fields_options [Hash] :hint (nil) the parameters that will be used to create the hint for the field, see {govuk_hint}.
|
85
|
+
# If no hint is given then no hint will be rendered
|
86
|
+
# @option govuk_fields_options [Hash] :field_options ({}) the options that will be used when rendering the fields.
|
87
|
+
# For more details look at a module that uses +Field+.
|
88
|
+
#
|
89
|
+
# @yield the fields HTML
|
90
|
+
#
|
91
|
+
# @yieldparam govuk_fields_options [Hash] the HTML options used when rendering the fields
|
92
|
+
# @yieldparam error_message [String] flag to indicate if there are any erros
|
93
|
+
#
|
94
|
+
# @return [ActiveSupport::SafeBuffer] the HTML that wraps arround the fields
|
95
|
+
|
96
|
+
def govuk_fields(field, attribute, **govuk_fields_options)
|
97
|
+
set_hint_id(attribute, govuk_fields_options)
|
98
|
+
error_message = find_field_error_message(attribute, govuk_fields_options)
|
99
|
+
|
100
|
+
govuk_form_group(attribute, error_message: error_message, **(govuk_fields_options[:form_group] || {})) do |display_error_message|
|
101
|
+
set_field_described_by(:fieldset, attribute, error_message, govuk_fields_options)
|
102
|
+
(govuk_fields_options[field] ||= {})[:attributes] ||= {}
|
103
|
+
|
104
|
+
govuk_fieldset(**govuk_fields_options[:fieldset]) do
|
105
|
+
concat(capture do
|
106
|
+
concat(govuk_hint(govuk_fields_options[:hint][:text], **govuk_fields_options[:hint])) if govuk_fields_options[:hint]
|
107
|
+
concat(display_error_message)
|
108
|
+
yield(govuk_fields_options[field], error_message)
|
109
|
+
end)
|
110
|
+
end
|
109
111
|
end
|
110
112
|
end
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
113
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
114
|
+
private
|
115
|
+
|
116
|
+
# If present, will find the error message for the field
|
117
|
+
#
|
118
|
+
# @param attribute [String, Symbol] the attribute of the fields
|
119
|
+
#
|
120
|
+
# @option govuk_field_options [String] :error_message (nil) the error message to be displayed
|
121
|
+
# @option govuk_field_options [ActiveModel] :model (nil) optional model that can be used to find an error message
|
122
|
+
# @option govuk_field_options [ActionView::Helpers::FormBuilder] :form (nil) optional form builder used to create
|
123
|
+
# the field and find the error message
|
124
|
+
#
|
125
|
+
# @return [String] the error message
|
126
|
+
|
127
|
+
def find_field_error_message(attribute, govuk_field_options)
|
128
|
+
if govuk_field_options[:model]
|
129
|
+
govuk_field_options[:model].errors[attribute].first
|
130
|
+
elsif govuk_field_options[:form]
|
131
|
+
govuk_field_options[:form].object.errors[attribute].first
|
132
|
+
else
|
133
|
+
govuk_field_options[:error_message]
|
134
|
+
end
|
133
135
|
end
|
134
|
-
end
|
135
136
|
|
136
|
-
|
137
|
-
|
138
|
-
|
137
|
+
# Sets the label +for+ if a custom ID has been given for the field.
|
138
|
+
#
|
139
|
+
# @param govuk_field_options [Hash] see {govuk_field} for details
|
139
140
|
|
140
|
-
|
141
|
-
|
141
|
+
def set_label_for_if_custom_id(field, govuk_field_options)
|
142
|
+
field_id = govuk_field_options.dig(field, :attributes, :id)
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
144
|
+
govuk_field_options[:label] ||= {}
|
145
|
+
(govuk_field_options[:label][:attributes] ||= {}).merge!({ for: field_id }) if field_id
|
146
|
+
end
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
# Sets the hint ID if there is a hint, and the ID for the hint has not been sent
|
149
|
+
#
|
150
|
+
# @param attribute [String, Symbol] the attribute of the field
|
151
|
+
# @param govuk_field_options [Hash] see {govuk_field} for details
|
151
152
|
|
152
|
-
|
153
|
-
|
153
|
+
def set_hint_id(attribute, govuk_field_options)
|
154
|
+
return if !govuk_field_options[:hint] || govuk_field_options.dig(:hint, :attributes, :id)
|
154
155
|
|
155
|
-
|
156
|
-
|
157
|
-
|
156
|
+
govuk_field_options[:hint] ||= {}
|
157
|
+
(govuk_field_options[:hint][:attributes] ||= {}).merge!({ id: "#{attribute}-hint" })
|
158
|
+
end
|
158
159
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
160
|
+
# Adds the aira-describedby attribute for the field
|
161
|
+
# if there is a hint or an error message
|
162
|
+
#
|
163
|
+
# @param attribute [String, Symbol] the attribute of the input
|
164
|
+
# @param error_message [String] used to indicate if there is an error
|
165
|
+
# @param govuk_field_options [Hash] see {#govuk_field} for details
|
165
166
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
167
|
+
def set_field_described_by(field, attribute, error_message, govuk_field_options)
|
168
|
+
aria_described_by = []
|
169
|
+
aria_described_by << govuk_field_options.dig(field, :attributes, :aria, :describedby)
|
170
|
+
aria_described_by << govuk_field_options[:hint][:attributes][:id] if govuk_field_options[:hint]
|
171
|
+
aria_described_by << "#{attribute}-error" if error_message
|
172
|
+
aria_described_by.compact!
|
172
173
|
|
173
|
-
|
174
|
-
|
174
|
+
govuk_field_options[field] ||= {}
|
175
|
+
govuk_field_options[field][:attributes] ||= {}
|
175
176
|
|
176
|
-
|
177
|
+
return unless aria_described_by.any?
|
177
178
|
|
178
|
-
|
179
|
-
|
179
|
+
(govuk_field_options[field][:attributes][:aria] ||= {}).merge!({ describedby: aria_described_by.join(' ') })
|
180
|
+
end
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
182
|
+
# Sets the hint attributes and adds the aira-describedby attribute for a fields item
|
183
|
+
#
|
184
|
+
# @param type [String] the type of the item
|
185
|
+
# @param attribute [String, Symbol] the attribute of the item
|
186
|
+
# @param item [Hash] the options for that item
|
186
187
|
|
187
|
-
|
188
|
-
|
188
|
+
def set_item_options_for_hint(type, attribute, item)
|
189
|
+
return unless item[:hint]
|
189
190
|
|
190
|
-
|
191
|
-
|
192
|
-
|
191
|
+
(item[:hint] ||= {})[:attributes] ||= {}
|
192
|
+
item[:hint][:classes] = "govuk-#{type}__hint #{item[:hint][:classes]}".rstrip
|
193
|
+
item[:hint][:attributes][:id] ||= "#{attribute}_#{item[:value]}-item-hint"
|
193
194
|
|
194
|
-
|
195
|
-
|
195
|
+
(item[:attributes][:aria] ||= {})[:describedby] = item[:hint][:attributes][:id]
|
196
|
+
end
|
196
197
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
198
|
+
# Sets the conditional attributes and adds the data-aira-controls attribute for a fields item
|
199
|
+
#
|
200
|
+
# @param type [String] the type of the item
|
201
|
+
# @param attribute [String, Symbol] the attribute of the item
|
202
|
+
# @param item [Hash] the options for that item
|
202
203
|
|
203
|
-
|
204
|
-
|
204
|
+
def set_conditional_item_options(type, attribute, item)
|
205
|
+
return unless item[:conditional]
|
205
206
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
207
|
+
item[:conditional][:attributes] ||= {}
|
208
|
+
item[:conditional][:attributes][:class] = "govuk-#{type}__conditional #{"govuk-#{type}__conditional--hidden" unless item[:checked]}".rstrip
|
209
|
+
item[:conditional][:attributes][:id] ||= sanitize_to_id("#{attribute}_#{item[:value]}_conditional")
|
210
|
+
(item[:attributes][:data] ||= {})[:'aria-controls'] = item[:conditional][:attributes][:id]
|
211
|
+
end
|
210
212
|
end
|
211
213
|
end
|
212
214
|
end
|
213
|
-
end
|
214
215
|
|
215
|
-
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|
216
|
+
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|
217
|
+
end
|