crown_marketplace_utils 0.1.0.beta.3 → 0.1.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/lib/crown_marketplace_utils/gov_uk_helper/button.rb +2 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field/character_count.rb +35 -38
- data/lib/crown_marketplace_utils/gov_uk_helper/field/checkboxes.rb +36 -26
- data/lib/crown_marketplace_utils/gov_uk_helper/field/date_input.rb +234 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field/file_upload.rb +125 -0
- data/lib/crown_marketplace_utils/gov_uk_helper/field/input.rb +53 -19
- data/lib/crown_marketplace_utils/gov_uk_helper/field/radios.rb +37 -23
- data/lib/crown_marketplace_utils/gov_uk_helper/field/select.rb +52 -48
- data/lib/crown_marketplace_utils/gov_uk_helper/field/textarea.rb +48 -35
- data/lib/crown_marketplace_utils/gov_uk_helper/field.rb +138 -96
- data/lib/crown_marketplace_utils/gov_uk_helper/fieldset.rb +1 -1
- data/lib/crown_marketplace_utils/gov_uk_helper/header.rb +2 -2
- data/lib/crown_marketplace_utils/gov_uk_helper/label.rb +1 -1
- data/lib/crown_marketplace_utils/gov_uk_helper/pagination.rb +1 -1
- data/lib/crown_marketplace_utils/gov_uk_helper.rb +4 -0
- data/lib/crown_marketplace_utils/version.rb +1 -1
- metadata +4 -2
@@ -21,11 +21,11 @@ module CrownMarketplaceUtils
|
|
21
21
|
# @param error_message [String] the error message to be displayed
|
22
22
|
# @param govuk_textarea_options [Hash] options that will be used for the parts of the form group, label, hint and textarea
|
23
23
|
#
|
24
|
-
# @option govuk_textarea_options [Hash] :
|
24
|
+
# @option govuk_textarea_options [Hash] :form_group see {govuk_field}
|
25
25
|
# @option govuk_textarea_options [Hash] :label see {govuk_field}
|
26
26
|
# @option govuk_textarea_options [Hash] :hint see {govuk_field}
|
27
|
-
# @option govuk_textarea_options [Hash] :
|
28
|
-
#
|
27
|
+
# @option govuk_textarea_options [Hash] :textarea ({}) the options that will be used when rendering the textarea.
|
28
|
+
# See {govuk_textarea_field} for more details.
|
29
29
|
#
|
30
30
|
# @return [ActiveSupport::SafeBuffer] the HTML for the GOV.UK textarea
|
31
31
|
# which can then be rendered on the page
|
@@ -36,18 +36,33 @@ module CrownMarketplaceUtils
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
# Generates the HTML for the GOV.UK textarea component using an ActiveModel.
|
40
|
+
# Unlike {#govuk_textarea}, the method will be able to automatically determine if the error message needs to be shown.
|
41
|
+
#
|
42
|
+
# @param model [ActiveModel] model that will be used to find an error message and content of the textarea
|
43
|
+
# @param attribute [String, Symbol] the attribute of the textarea
|
44
|
+
# @param govuk_textarea_options [Hash] options that will be used for the parts of the form group, label, hint and textarea
|
45
|
+
#
|
46
|
+
# @option (see govuk_textarea)
|
47
|
+
#
|
48
|
+
# @return (see govuk_textarea)
|
49
|
+
|
50
|
+
def govuk_textarea_with_model(model, attribute, **govuk_textarea_options)
|
51
|
+
(govuk_textarea_options[:textarea] ||= {})[:content] = model.send(attribute)
|
52
|
+
|
53
|
+
govuk_field_with_model(:textarea, model, attribute, **govuk_textarea_options) do |govuk_field_options, error_message|
|
54
|
+
concat(govuk_textarea_field(attribute, error_message, **govuk_field_options))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
39
58
|
# Generates the HTML for the GOV.UK textarea component using an ActionView::Helpers::FormBuilder.
|
40
59
|
# Unlike {#govuk_textarea}, the method will be able to automatically determine if the error message needs to be shown.
|
41
60
|
#
|
42
|
-
# @param form [ActionView::Helpers::FormBuilder]
|
61
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the textarea
|
43
62
|
# @param attribute [String, Symbol] the attribute of the textarea
|
44
63
|
# @param govuk_textarea_options [Hash] options that will be used for the parts of the form group, label, hint and textarea
|
45
64
|
#
|
46
|
-
# @option
|
47
|
-
# @option govuk_textarea_options [Hash] :label see {govuk_field_with_form}
|
48
|
-
# @option govuk_textarea_options [Hash] :hint see {govuk_field_with_form}
|
49
|
-
# @option govuk_textarea_options [Hash] :textarea_options ({}) the options that will be used when rendering the textarea.
|
50
|
-
# See {govuk_textarea_field_with_form} for more details.
|
65
|
+
# @option (see govuk_textarea)
|
51
66
|
#
|
52
67
|
# @return (see govuk_textarea)
|
53
68
|
|
@@ -65,34 +80,45 @@ module CrownMarketplaceUtils
|
|
65
80
|
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
66
81
|
# @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
|
67
82
|
#
|
68
|
-
# @option (see
|
83
|
+
# @option (see set_govuk_textarea_field_options)
|
69
84
|
#
|
70
85
|
# @return [ActiveSupport::SafeBuffer] the HTML for the textarea field which is used in {govuk_textarea}
|
71
86
|
|
72
87
|
def govuk_textarea_field(attribute, error_message, **govuk_text_textarea_options)
|
73
|
-
|
74
|
-
|
75
|
-
|
88
|
+
set_govuk_textarea_field_options(error_message, govuk_text_textarea_options)
|
89
|
+
|
90
|
+
text_area_tag(
|
91
|
+
attribute,
|
92
|
+
govuk_text_textarea_options[:content],
|
93
|
+
class: govuk_text_textarea_options[:classes],
|
94
|
+
rows: govuk_text_textarea_options[:rows],
|
95
|
+
**govuk_text_textarea_options[:attributes]
|
96
|
+
)
|
76
97
|
end
|
77
98
|
|
78
99
|
# Generates the textarea HTML for {govuk_textarea_with_form}
|
79
100
|
#
|
80
|
-
# @param form [ActionView::Helpers::FormBuilder]
|
101
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the textarea
|
81
102
|
# @param attribute [String, Symbol] the attribute of the textarea
|
82
103
|
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
83
104
|
# @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
|
84
105
|
#
|
85
|
-
# @option (see
|
106
|
+
# @option (see set_govuk_textarea_field_options)
|
86
107
|
#
|
87
108
|
# @return [ActiveSupport::SafeBuffer] the HTML for the textarea field which is used in {govuk_textarea_with_form}
|
88
109
|
|
89
110
|
def govuk_textarea_field_with_form(form, attribute, error_message, **govuk_text_textarea_options)
|
90
|
-
|
91
|
-
|
92
|
-
|
111
|
+
set_govuk_textarea_field_options(error_message, govuk_text_textarea_options)
|
112
|
+
|
113
|
+
form.text_area(
|
114
|
+
attribute,
|
115
|
+
class: govuk_text_textarea_options[:classes],
|
116
|
+
rows: govuk_text_textarea_options[:rows],
|
117
|
+
**govuk_text_textarea_options[:attributes]
|
118
|
+
)
|
93
119
|
end
|
94
120
|
|
95
|
-
#
|
121
|
+
# Initialises the attributes for the textarea input
|
96
122
|
#
|
97
123
|
# @param error_message [String] used to indicate if there is an error which will add extra classes
|
98
124
|
# @param govuk_text_textarea_options [Hash] options that will be used in customising the HTML
|
@@ -101,27 +127,14 @@ module CrownMarketplaceUtils
|
|
101
127
|
# @option govuk_text_textarea_options [String] :content (nil) the content of the textarea
|
102
128
|
# @option govuk_text_textarea_options [String] :rows (5) the number of rows for the text area
|
103
129
|
# @option govuk_text_textarea_options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML
|
104
|
-
#
|
105
|
-
# @yield the textarea HTML generated by {govuk_textarea_field} or {govuk_textarea_field_with_form}
|
106
|
-
#
|
107
|
-
# @yieldparam govuk_text_textarea_classes [Array] the classes for the label HTML
|
108
|
-
# @yieldparam govuk_text_textarea_rows [Integer, String] (5) the number of rows for the text area
|
109
|
-
# @yieldparam govuk_text_textarea_attributes [Hash] additional attributes that will added as part of the HTML
|
110
|
-
#
|
111
|
-
# @return [ActiveSupport::SafeBuffer] the HTML for the textarea field which is used in {govuk_textarea_field} or {govuk_textarea_field_with_form}
|
112
130
|
|
113
|
-
def
|
114
|
-
|
115
|
-
|
116
|
-
govuk_text_textarea_classes << govuk_text_textarea_options[:classes]
|
131
|
+
def set_govuk_textarea_field_options(error_message, govuk_text_textarea_options)
|
132
|
+
govuk_text_textarea_options[:classes] = "govuk-textarea #{govuk_text_textarea_options[:classes]}".rstrip
|
133
|
+
govuk_text_textarea_options[:classes] << ' govuk-textarea--error' if error_message
|
117
134
|
govuk_text_textarea_options[:attributes] ||= {}
|
118
135
|
govuk_text_textarea_options[:rows] ||= 5
|
119
|
-
|
120
|
-
yield(govuk_text_textarea_classes, govuk_text_textarea_options[:rows], govuk_text_textarea_options[:attributes])
|
121
136
|
end
|
122
137
|
end
|
123
138
|
end
|
124
139
|
end
|
125
140
|
end
|
126
|
-
|
127
|
-
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|
@@ -7,6 +7,8 @@ require_relative 'label'
|
|
7
7
|
|
8
8
|
module CrownMarketplaceUtils
|
9
9
|
module GovUkHelper
|
10
|
+
# rubocop:disable Metrics/ModuleLength
|
11
|
+
|
10
12
|
# = GOV.UK Field
|
11
13
|
#
|
12
14
|
# This module contains methods to wrap the:
|
@@ -28,21 +30,17 @@ module CrownMarketplaceUtils
|
|
28
30
|
|
29
31
|
# Generates the HTML to wrap arround a GDS input field component.
|
30
32
|
#
|
31
|
-
# @param
|
33
|
+
# @param field [Symbol] the type of the field
|
32
34
|
# @param attribute [String, Symbol] the attribute of the field
|
33
35
|
# @param error_message [String] the error message to be displayed
|
34
36
|
# @param govuk_field_options [Hash] options that will be used for the parts of the form group, label, hint and field
|
35
37
|
#
|
36
|
-
# @option govuk_field_options [Hash] :
|
37
|
-
# @option govuk_field_options [Hash] :label the parameters that will be used to create the label for the field
|
38
|
-
#
|
39
|
-
# - +:options+ - default: { } - the options for govuk_label {govuk_label}
|
40
|
-
# @option govuk_field_options [Hash] :hint (nil) the parameters that will be used to create the hint for the field
|
41
|
-
# - +:text+ (required) - the hint text
|
42
|
-
# - +:options+ - default: { } - the options for govuk_hint {govuk_hint}
|
38
|
+
# @option govuk_field_options [Hash] :form_group ({}) the options for govuk_form_group {govuk_form_group}
|
39
|
+
# @option govuk_field_options [Hash] :label the parameters that will be used to create the label for the field, see {govuk_label}
|
40
|
+
# @option govuk_field_options [Hash] :hint (nil) the parameters that will be used to create the hint for the field, see {govuk_hint}.
|
43
41
|
# If no hint is given then no hint will be rendered
|
44
42
|
# @option govuk_field_options [Hash] :field_options ({}) the options that will be used when rendering the field.
|
45
|
-
# For more details look at
|
43
|
+
# For more details look at the specific module that uses +Field+.
|
46
44
|
#
|
47
45
|
# @yield the field HTML
|
48
46
|
#
|
@@ -50,20 +48,51 @@ module CrownMarketplaceUtils
|
|
50
48
|
#
|
51
49
|
# @return [ActiveSupport::SafeBuffer] the HTML that wraps arround the field
|
52
50
|
|
53
|
-
def govuk_field(
|
54
|
-
|
51
|
+
def govuk_field(field, attribute, error_message = nil, **govuk_field_options)
|
52
|
+
set_label_for_if_custom_id(field, govuk_field_options)
|
53
|
+
set_hint_id(attribute, govuk_field_options)
|
54
|
+
|
55
|
+
govuk_form_group(attribute, error_message, **(govuk_field_options[:form_group] || {})) do |display_error_message|
|
56
|
+
set_field_described_by(field, attribute, error_message, govuk_field_options)
|
55
57
|
|
56
|
-
|
58
|
+
capture do
|
59
|
+
concat(govuk_label(attribute, govuk_field_options[:label][:text], **govuk_field_options[:label]))
|
60
|
+
concat(govuk_hint(govuk_field_options[:hint][:text], **govuk_field_options[:hint])) if govuk_field_options[:hint]
|
61
|
+
concat(display_error_message)
|
62
|
+
yield(govuk_field_options[field])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Generates the HTML to wrap arround a GDS input field component using an ActiveModel.
|
68
|
+
# Unlike {govuk_field}, the method will be able to automatically determine if the error message needs to be shown.
|
69
|
+
#
|
70
|
+
# @param field [Symbol] the type of the field
|
71
|
+
# @param model [ActiveModel] model that will be used to find an error message
|
72
|
+
# @param attribute [String, Symbol] the attribute of the field
|
73
|
+
# @param govuk_field_options [Hash] options that will be used for the parts of the form group, label, hint and field
|
74
|
+
#
|
75
|
+
# @option (see govuk_field)
|
76
|
+
#
|
77
|
+
# @yield (see govuk_field)
|
78
|
+
#
|
79
|
+
# @yieldparam (see govuk_field)
|
80
|
+
# @yieldparam error_message [ActiveSupport::SafeBuffer] used by the field to indicate if there is an error
|
81
|
+
#
|
82
|
+
# @return (see govuk_field)
|
83
|
+
|
84
|
+
def govuk_field_with_model(field, model, attribute, **govuk_field_options)
|
85
|
+
set_label_for_if_custom_id(field, govuk_field_options)
|
57
86
|
set_hint_id(attribute, govuk_field_options)
|
58
87
|
|
59
|
-
|
60
|
-
set_field_described_by(
|
88
|
+
govuk_form_group_with_model(model, attribute, **(govuk_field_options[:form_group] || {})) do |display_error_message|
|
89
|
+
set_field_described_by(field, attribute, display_error_message, govuk_field_options)
|
61
90
|
|
62
91
|
capture do
|
63
|
-
concat(govuk_label(attribute, govuk_field_options[:label][:text], **govuk_field_options[:label]
|
64
|
-
concat(govuk_hint(govuk_field_options[:hint][:text], **govuk_field_options[:hint]
|
92
|
+
concat(govuk_label(attribute, govuk_field_options[:label][:text], **govuk_field_options[:label]))
|
93
|
+
concat(govuk_hint(govuk_field_options[:hint][:text], **govuk_field_options[:hint])) if govuk_field_options[:hint]
|
65
94
|
concat(display_error_message)
|
66
|
-
yield(govuk_field_options[
|
95
|
+
yield(govuk_field_options[field], display_error_message)
|
67
96
|
end
|
68
97
|
end
|
69
98
|
end
|
@@ -71,43 +100,32 @@ module CrownMarketplaceUtils
|
|
71
100
|
# Generates the HTML to wrap arround a GDS input field component using an ActionView::Helpers::FormBuilder.
|
72
101
|
# Unlike {govuk_field}, the method will be able to automatically determine if the error message needs to be shown.
|
73
102
|
#
|
74
|
-
# @param
|
75
|
-
# @param form [ActionView::Helpers::FormBuilder]
|
103
|
+
# @param field [Symbol] the type of the field
|
104
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the label
|
76
105
|
# @param attribute [String, Symbol] the attribute of the field
|
77
106
|
# @param govuk_field_options [Hash] options that will be used for the parts of the form group, label, hint and field
|
78
107
|
#
|
79
|
-
# @option
|
80
|
-
# @option govuk_field_options [Hash] :label the parameters that will be used to create the label for the field:
|
81
|
-
# - +:text+ (required) - the label text
|
82
|
-
# - +:options+ - default: { } - the options for govuk_label {govuk_label}
|
83
|
-
# @option govuk_field_options [Hash] :hint (nil) the parameters that will be used to create the hint for the field
|
84
|
-
# - +:text+ (required) - the hint text
|
85
|
-
# - +:options+ - default: { } - the options for govuk_hint {govuk_hint}
|
86
|
-
# If no hint is given then no hint will be rendered
|
87
|
-
# @option govuk_field_options [Hash] :field_options ({}) the options that will be used when rendering the field.
|
88
|
-
# For more details look at a module that uses +Field+.
|
108
|
+
# @option (see govuk_field)
|
89
109
|
#
|
90
|
-
# @yield
|
110
|
+
# @yield (see govuk_field)
|
91
111
|
#
|
92
|
-
# @yieldparam
|
112
|
+
# @yieldparam (see govuk_field)
|
93
113
|
# @yieldparam error_message [ActiveSupport::SafeBuffer] used by the field to indicate if there is an error
|
94
114
|
#
|
95
115
|
# @return (see govuk_field)
|
96
116
|
|
97
|
-
def govuk_field_with_form(
|
98
|
-
|
99
|
-
|
100
|
-
set_label_for_if_custom_id(field_key, govuk_field_options)
|
117
|
+
def govuk_field_with_form(field, form, attribute, **govuk_field_options)
|
118
|
+
set_label_for_if_custom_id(field, govuk_field_options)
|
101
119
|
set_hint_id(attribute, govuk_field_options)
|
102
120
|
|
103
|
-
govuk_form_group_with_model(form.object, attribute, **(govuk_field_options[:
|
104
|
-
set_field_described_by(
|
121
|
+
govuk_form_group_with_model(form.object, attribute, **(govuk_field_options[:form_group] || {})) do |display_error_message|
|
122
|
+
set_field_described_by(field, attribute, display_error_message, govuk_field_options)
|
105
123
|
|
106
124
|
capture do
|
107
|
-
concat(govuk_label_with_form(form, attribute, govuk_field_options[:label][:text], **(govuk_field_options[:label]
|
108
|
-
concat(govuk_hint(govuk_field_options[:hint][:text], **govuk_field_options[:hint]
|
125
|
+
concat(govuk_label_with_form(form, attribute, govuk_field_options[:label][:text], **(govuk_field_options[:label] || {})))
|
126
|
+
concat(govuk_hint(govuk_field_options[:hint][:text], **govuk_field_options[:hint])) if govuk_field_options[:hint]
|
109
127
|
concat(display_error_message)
|
110
|
-
yield(govuk_field_options[
|
128
|
+
yield(govuk_field_options[field], display_error_message)
|
111
129
|
end
|
112
130
|
end
|
113
131
|
end
|
@@ -115,16 +133,14 @@ module CrownMarketplaceUtils
|
|
115
133
|
# Generates the HTML to wrap arround a GDS input fields component.
|
116
134
|
# These are inputs that require being wrapped in a fieldset, for example radio buttons.
|
117
135
|
#
|
118
|
-
# @param
|
136
|
+
# @param field [Symbol] the type of the fields
|
119
137
|
# @param attribute [String, Symbol] the attribute of the fields
|
120
138
|
# @param error_message [String] the error message to be displayed
|
121
139
|
# @param govuk_fields_options [Hash] options that will be used for the parts of the fieldset, form group, hint and fields
|
122
140
|
#
|
123
|
-
# @option govuk_fields_options [Hash] :
|
124
|
-
# @option govuk_fields_options [Hash] :
|
125
|
-
# @option govuk_fields_options [Hash] :hint (nil) the parameters that will be used to create the hint for the
|
126
|
-
# - +:text+ (required) - the hint text
|
127
|
-
# - +:options+ - default: { } - the options for govuk_hint {govuk_hint}
|
141
|
+
# @option govuk_fields_options [Hash] :form_group ({}) the options for govuk_form_group {govuk_form_group}
|
142
|
+
# @option govuk_fields_options [Hash] :fieldset ({}) the options for govuk_fieldset {govuk_fieldset}
|
143
|
+
# @option govuk_fields_options [Hash] :hint (nil) the parameters that will be used to create the hint for the field, see {govuk_hint}.
|
128
144
|
# If no hint is given then no hint will be rendered
|
129
145
|
# @option govuk_fields_options [Hash] :field_options ({}) the options that will be used when rendering the fields.
|
130
146
|
# For more details look at a module that uses +Field+.
|
@@ -135,21 +151,53 @@ module CrownMarketplaceUtils
|
|
135
151
|
#
|
136
152
|
# @return [ActiveSupport::SafeBuffer] the HTML that wraps arround the fields
|
137
153
|
|
138
|
-
def govuk_fields(
|
139
|
-
|
154
|
+
def govuk_fields(field, attribute, error_message = nil, **govuk_fields_options)
|
155
|
+
set_hint_id(attribute, govuk_fields_options)
|
156
|
+
|
157
|
+
govuk_form_group(attribute, error_message, **(govuk_fields_options[:form_group] || {})) do |display_error_message|
|
158
|
+
set_field_described_by(:fieldset, attribute, error_message, govuk_fields_options)
|
159
|
+
(govuk_fields_options[field] ||= {})[:attributes] ||= {}
|
160
|
+
|
161
|
+
govuk_fieldset(**govuk_fields_options[:fieldset]) do
|
162
|
+
concat(capture do
|
163
|
+
concat(govuk_hint(govuk_fields_options[:hint][:text], **govuk_fields_options[:hint])) if govuk_fields_options[:hint]
|
164
|
+
concat(display_error_message)
|
165
|
+
yield(govuk_fields_options[field])
|
166
|
+
end)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# Generates the HTML to wrap arround a GDS input fields component using an ActiveModel.
|
172
|
+
# These are inputs that require being wrapped in a fieldset, for example radio buttons.
|
173
|
+
#
|
174
|
+
# @param field [Symbol] the type of the fields
|
175
|
+
# @param model [ActiveModel] model that will be used to find an error message
|
176
|
+
# @param attribute [String, Symbol] the attribute of the fields
|
177
|
+
# @param govuk_fields_options [Hash] options that will be used for the parts of the fieldset, form group, hint and fields
|
178
|
+
#
|
179
|
+
# @option (see govuk_fields)
|
180
|
+
#
|
181
|
+
# @yield (see govuk_fields)
|
182
|
+
#
|
183
|
+
# @yieldparam (see govuk_fields)
|
184
|
+
# @yieldparam any_errors flag to indicate if there are errors present
|
185
|
+
#
|
186
|
+
# @return (see govuk_fields)
|
140
187
|
|
188
|
+
def govuk_fields_with_model(field, model, attribute, **govuk_fields_options)
|
141
189
|
set_hint_id(attribute, govuk_fields_options)
|
142
190
|
|
143
|
-
|
144
|
-
set_field_described_by(:
|
145
|
-
(govuk_fields_options[
|
191
|
+
govuk_form_group_with_model(model, attribute, **(govuk_fields_options[:form_group] || {})) do |display_error_message|
|
192
|
+
set_field_described_by(:fieldset, attribute, display_error_message, govuk_fields_options)
|
193
|
+
(govuk_fields_options[field] ||= {})[:attributes] ||= {}
|
146
194
|
|
147
|
-
govuk_fieldset(**govuk_fields_options[:
|
148
|
-
capture do
|
149
|
-
concat(govuk_hint(govuk_fields_options[:hint][:text], **govuk_fields_options[:hint]
|
195
|
+
govuk_fieldset(**govuk_fields_options[:fieldset]) do
|
196
|
+
concat(capture do
|
197
|
+
concat(govuk_hint(govuk_fields_options[:hint][:text], **govuk_fields_options[:hint])) if govuk_fields_options[:hint]
|
150
198
|
concat(display_error_message)
|
151
|
-
yield(govuk_fields_options[
|
152
|
-
end
|
199
|
+
yield(govuk_fields_options[field], display_error_message)
|
200
|
+
end)
|
153
201
|
end
|
154
202
|
end
|
155
203
|
end
|
@@ -159,41 +207,32 @@ module CrownMarketplaceUtils
|
|
159
207
|
#
|
160
208
|
# Unlike {govuk_fields}, the method will be able to automatically determine if the error message needs to be shown.
|
161
209
|
#
|
162
|
-
# @param
|
163
|
-
# @param form [ActionView::Helpers::FormBuilder]
|
210
|
+
# @param field [Symbol] the type of the fields
|
211
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the label
|
164
212
|
# @param attribute [String, Symbol] the attribute of the fields
|
165
213
|
# @param govuk_fields_options [Hash] options that will be used for the parts of the fieldset, form group, hint and fields
|
166
214
|
#
|
167
|
-
# @option
|
168
|
-
# @option govuk_fields_options [Hash] :fieldset_options ({}) the options for govuk_fieldset {govuk_fieldset}
|
169
|
-
# @option govuk_fields_options [Hash] :hint (nil) the parameters that will be used to create the hint for the fields
|
170
|
-
# - +:text+ (required) - the hint text
|
171
|
-
# - +:options+ - default: { } - the options for govuk_hint {govuk_hint}
|
172
|
-
# If no hint is given then no hint will be rendered
|
173
|
-
# @option govuk_fields_options [Hash] :field_options ({}) the options that will be used when rendering the fields.
|
174
|
-
# For more details look at a module that uses +Field+.
|
215
|
+
# @option (see govuk_fields)
|
175
216
|
#
|
176
|
-
# @yield
|
217
|
+
# @yield (see govuk_fields)
|
177
218
|
#
|
178
|
-
# @yieldparam
|
219
|
+
# @yieldparam (see govuk_fields_with_model)
|
179
220
|
#
|
180
221
|
# @return (see govuk_fields)
|
181
222
|
|
182
|
-
def govuk_fields_with_form(
|
183
|
-
field_key = :"#{type}_options"
|
184
|
-
|
223
|
+
def govuk_fields_with_form(field, form, attribute, **govuk_fields_options)
|
185
224
|
set_hint_id(attribute, govuk_fields_options)
|
186
225
|
|
187
|
-
govuk_form_group_with_model(form.object, attribute, **(govuk_fields_options[:
|
188
|
-
set_field_described_by(:
|
189
|
-
(govuk_fields_options[
|
226
|
+
govuk_form_group_with_model(form.object, attribute, **(govuk_fields_options[:form_group] || {})) do |display_error_message|
|
227
|
+
set_field_described_by(:fieldset, attribute, display_error_message, govuk_fields_options)
|
228
|
+
(govuk_fields_options[field] ||= {})[:attributes] ||= {}
|
190
229
|
|
191
|
-
govuk_fieldset(**govuk_fields_options[:
|
192
|
-
capture do
|
193
|
-
concat(govuk_hint(govuk_fields_options[:hint][:text], **govuk_fields_options[:hint]
|
230
|
+
govuk_fieldset(**govuk_fields_options[:fieldset]) do
|
231
|
+
concat(capture do
|
232
|
+
concat(govuk_hint(govuk_fields_options[:hint][:text], **govuk_fields_options[:hint])) if govuk_fields_options[:hint]
|
194
233
|
concat(display_error_message)
|
195
|
-
yield(govuk_fields_options[
|
196
|
-
end
|
234
|
+
yield(govuk_fields_options[field], display_error_message)
|
235
|
+
end)
|
197
236
|
end
|
198
237
|
end
|
199
238
|
end
|
@@ -204,11 +243,11 @@ module CrownMarketplaceUtils
|
|
204
243
|
#
|
205
244
|
# @param govuk_field_options [Hash] see {govuk_field} for details
|
206
245
|
|
207
|
-
def set_label_for_if_custom_id(
|
208
|
-
field_id = govuk_field_options.dig(
|
246
|
+
def set_label_for_if_custom_id(field, govuk_field_options)
|
247
|
+
field_id = govuk_field_options.dig(field, :attributes, :id)
|
209
248
|
|
210
|
-
govuk_field_options[:label]
|
211
|
-
(govuk_field_options[:label][:
|
249
|
+
govuk_field_options[:label] ||= {}
|
250
|
+
(govuk_field_options[:label][:attributes] ||= {}).merge!({ for: field_id }) if field_id
|
212
251
|
end
|
213
252
|
|
214
253
|
# Sets the hint ID if there is a hint, and the ID for the hint has not been sent
|
@@ -217,10 +256,10 @@ module CrownMarketplaceUtils
|
|
217
256
|
# @param govuk_field_options [Hash] see {govuk_field} for details
|
218
257
|
|
219
258
|
def set_hint_id(attribute, govuk_field_options)
|
220
|
-
return if !govuk_field_options[:hint] || govuk_field_options.dig(:hint, :
|
259
|
+
return if !govuk_field_options[:hint] || govuk_field_options.dig(:hint, :attributes, :id)
|
221
260
|
|
222
|
-
govuk_field_options[:hint]
|
223
|
-
(govuk_field_options[:hint][:
|
261
|
+
govuk_field_options[:hint] ||= {}
|
262
|
+
(govuk_field_options[:hint][:attributes] ||= {}).merge!({ id: "#{attribute}-hint" })
|
224
263
|
end
|
225
264
|
|
226
265
|
# Adds the aira-describedby attribute for the field
|
@@ -230,19 +269,19 @@ module CrownMarketplaceUtils
|
|
230
269
|
# @param error_message [String] used to indicate if there is an error
|
231
270
|
# @param govuk_field_options [Hash] see {#govuk_field} for details
|
232
271
|
|
233
|
-
def set_field_described_by(
|
272
|
+
def set_field_described_by(field, attribute, error_message, govuk_field_options)
|
234
273
|
aria_described_by = []
|
235
|
-
aria_described_by << govuk_field_options.dig(
|
236
|
-
aria_described_by << govuk_field_options[:hint][:
|
274
|
+
aria_described_by << govuk_field_options.dig(field, :attributes, :aria, :describedby)
|
275
|
+
aria_described_by << govuk_field_options[:hint][:attributes][:id] if govuk_field_options[:hint]
|
237
276
|
aria_described_by << "#{attribute}-error" if error_message
|
238
277
|
aria_described_by.compact!
|
239
278
|
|
240
|
-
govuk_field_options[
|
241
|
-
govuk_field_options[
|
279
|
+
govuk_field_options[field] ||= {}
|
280
|
+
govuk_field_options[field][:attributes] ||= {}
|
242
281
|
|
243
282
|
return unless aria_described_by.any?
|
244
283
|
|
245
|
-
(govuk_field_options[
|
284
|
+
(govuk_field_options[field][:attributes][:aria] ||= {}).merge!({ describedby: aria_described_by.join(' ') })
|
246
285
|
end
|
247
286
|
|
248
287
|
# Sets the hint classes and adds the aira-describedby attribute for a fields item
|
@@ -252,12 +291,15 @@ module CrownMarketplaceUtils
|
|
252
291
|
# @param item [Hash] the options for that item
|
253
292
|
|
254
293
|
def set_item_options_for_hint(type, attribute, item)
|
255
|
-
(item[:hint]
|
256
|
-
item[:hint][:
|
257
|
-
item[:hint][:
|
294
|
+
(item[:hint] ||= {})[:attributes] ||= {}
|
295
|
+
item[:hint][:classes] = "govuk-#{type}__hint #{item[:hint][:classes]}".rstrip
|
296
|
+
item[:hint][:attributes][:id] ||= "#{attribute}_#{item[:value]}-item-hint"
|
258
297
|
|
259
|
-
(item[:attributes][:aria] ||= {})[:describedby] = item[:hint][:
|
298
|
+
(item[:attributes][:aria] ||= {})[:describedby] = item[:hint][:attributes][:id]
|
260
299
|
end
|
261
300
|
end
|
301
|
+
# rubocop:enable Metrics/ModuleLength
|
262
302
|
end
|
263
303
|
end
|
304
|
+
|
305
|
+
ActionView::Base.field_error_proc = proc { |html_tag, _instance| html_tag }
|
@@ -35,7 +35,7 @@ module CrownMarketplaceUtils
|
|
35
35
|
tag.fieldset(class: govuk_fieldset_classes, **govuk_fieldset_options[:attributes]) do
|
36
36
|
capture do
|
37
37
|
concat(govuk_legend(govuk_fieldset_options[:legend])) if govuk_fieldset_options[:legend]
|
38
|
-
|
38
|
+
yield
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -44,8 +44,8 @@ module CrownMarketplaceUtils
|
|
44
44
|
if govuk_header_options[:service_options].present? || govuk_header_options[:navigation_options].present?
|
45
45
|
concat(tag.div(class: 'govuk-header__content') do
|
46
46
|
capture do
|
47
|
-
concat(govuk_header_service_name(service_options)) if govuk_header_options[:service_options].present?
|
48
|
-
concat(govuk_header_navigation(navigation_options)) if govuk_header_options[:navigation_options].present?
|
47
|
+
concat(govuk_header_service_name(govuk_header_options[:service_options])) if govuk_header_options[:service_options].present?
|
48
|
+
concat(govuk_header_navigation(govuk_header_options[:navigation_options])) if govuk_header_options[:navigation_options].present?
|
49
49
|
end
|
50
50
|
end)
|
51
51
|
end
|
@@ -43,7 +43,7 @@ module CrownMarketplaceUtils
|
|
43
43
|
|
44
44
|
# Generates the HTML for the GOV.UK label component using an ActionView::Helpers::FormBuilder
|
45
45
|
#
|
46
|
-
# @param form [ActionView::Helpers::FormBuilder]
|
46
|
+
# @param form [ActionView::Helpers::FormBuilder] the form builder used to create the label
|
47
47
|
# @param attribute [String, Symbol] the attribute of the input that requires a label
|
48
48
|
# @param label_text [String] the label text, it is ignored if a block is given
|
49
49
|
# @param govuk_label_options [Hash] options that will be used in customising the HTML
|
@@ -199,7 +199,7 @@ module CrownMarketplaceUtils
|
|
199
199
|
end
|
200
200
|
|
201
201
|
tag.li(class: govuk_pagination_item_classes) do
|
202
|
-
link_to(govuk_pagination_item[:
|
202
|
+
link_to(govuk_pagination_item[:number], govuk_pagination_item[:href], class: 'govuk-link govuk-pagination__link', **govuk_pagination_item[:attributes])
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
@@ -7,6 +7,8 @@ require_relative 'gov_uk_helper/error_message'
|
|
7
7
|
require_relative 'gov_uk_helper/field'
|
8
8
|
require_relative 'gov_uk_helper/field/character_count'
|
9
9
|
require_relative 'gov_uk_helper/field/checkboxes'
|
10
|
+
require_relative 'gov_uk_helper/field/date_input'
|
11
|
+
require_relative 'gov_uk_helper/field/file_upload'
|
10
12
|
require_relative 'gov_uk_helper/field/input'
|
11
13
|
require_relative 'gov_uk_helper/field/select'
|
12
14
|
require_relative 'gov_uk_helper/field/textarea'
|
@@ -33,6 +35,8 @@ module CrownMarketplaceUtils
|
|
33
35
|
include Field
|
34
36
|
include Field::CharacterCount
|
35
37
|
include Field::Checkboxes
|
38
|
+
include Field::DateInput
|
39
|
+
include Field::FileUpload
|
36
40
|
include Field::Input
|
37
41
|
include Field::Radios
|
38
42
|
include Field::Select
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crown_marketplace_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.beta.
|
4
|
+
version: 0.1.0.beta.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tim-s-ccs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -176,6 +176,8 @@ files:
|
|
176
176
|
- lib/crown_marketplace_utils/gov_uk_helper/field.rb
|
177
177
|
- lib/crown_marketplace_utils/gov_uk_helper/field/character_count.rb
|
178
178
|
- lib/crown_marketplace_utils/gov_uk_helper/field/checkboxes.rb
|
179
|
+
- lib/crown_marketplace_utils/gov_uk_helper/field/date_input.rb
|
180
|
+
- lib/crown_marketplace_utils/gov_uk_helper/field/file_upload.rb
|
179
181
|
- lib/crown_marketplace_utils/gov_uk_helper/field/input.rb
|
180
182
|
- lib/crown_marketplace_utils/gov_uk_helper/field/radios.rb
|
181
183
|
- lib/crown_marketplace_utils/gov_uk_helper/field/select.rb
|