govuk_design_system_formbuilder 1.0.0 → 1.1.0
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/lib/govuk_design_system_formbuilder/base.rb +5 -48
- data/lib/govuk_design_system_formbuilder/builder.rb +16 -10
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +5 -2
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +23 -8
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +1 -1
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +5 -2
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +3 -1
- data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +5 -6
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +6 -2
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +6 -2
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +4 -1
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/hint.rb +3 -1
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/date.rb +6 -2
- data/lib/govuk_design_system_formbuilder/elements/error_message.rb +3 -1
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +3 -1
- data/lib/govuk_design_system_formbuilder/elements/file.rb +6 -1
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +12 -2
- data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +6 -0
- data/lib/govuk_design_system_formbuilder/elements/label.rb +5 -3
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +6 -2
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +8 -4
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +3 -0
- data/lib/govuk_design_system_formbuilder/elements/select.rb +6 -1
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +39 -6
- data/lib/govuk_design_system_formbuilder/traits/collection_item.rb +16 -0
- data/lib/govuk_design_system_formbuilder/traits/conditional.rb +17 -0
- data/lib/govuk_design_system_formbuilder/traits/error.rb +17 -0
- data/lib/govuk_design_system_formbuilder/traits/hint.rb +17 -0
- data/lib/govuk_design_system_formbuilder/traits/input.rb +77 -0
- data/lib/govuk_design_system_formbuilder/traits/label.rb +11 -0
- data/lib/govuk_design_system_formbuilder/traits/localisation.rb +41 -0
- data/lib/govuk_design_system_formbuilder/traits/supplemental.rb +17 -0
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- data/lib/govuk_design_system_formbuilder.rb +78 -43
- metadata +43 -8
- data/lib/govuk_design_system_formbuilder/elements/inputs/base.rb +0 -79
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 22098ebab17cee5e2e294761537d450ee5c05234f4978dbacc16e7dfdf0796c0
|
|
4
|
+
data.tar.gz: 8c594545595dc3234931d9c27f649064d9b271fbc1edcd7cb1df1651226d9aa5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cec156f45571f7a8e3281735e689cf4a5412ba6780c7dbbb154ec35ee69cb63e75f8624225c3293c877c71aa6f33e8b09b7e9875ed3a7f4a7c913edaad21284c
|
|
7
|
+
data.tar.gz: 52d3d7456d4526a5f0d081f4838269f254e547b16e98f95570f1dbe56536fbc6c0547fcb85c7ea8595236b5de5912a087292fccbed343d81456659b0956c88b0
|
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
class Base
|
|
3
3
|
delegate :capture, :content_tag, :safe_join, :tag, :raw, :link_to, to: :@builder
|
|
4
|
+
delegate :config, to: GOVUKDesignSystemFormBuilder
|
|
4
5
|
|
|
5
6
|
def initialize(builder, object_name, attribute_name, &block)
|
|
6
|
-
@builder
|
|
7
|
-
@object_name
|
|
7
|
+
@builder = builder
|
|
8
|
+
@object_name = object_name
|
|
8
9
|
@attribute_name = attribute_name
|
|
9
|
-
@block_content
|
|
10
|
+
@block_content = capture { block.call } if block_given?
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, @hint_text)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def error_element
|
|
17
|
-
@error_element ||= Elements::ErrorMessage.new(@builder, @object_name, @attribute_name)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def label_element
|
|
21
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **@label)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def supplemental_content
|
|
25
|
-
@supplemental_content ||= Containers::Supplemental.new(@builder, @object_name, @attribute_name, @block_content)
|
|
26
|
-
end
|
|
13
|
+
private
|
|
27
14
|
|
|
28
15
|
# returns the id value used for the input
|
|
29
16
|
#
|
|
@@ -46,45 +33,15 @@ module GOVUKDesignSystemFormBuilder
|
|
|
46
33
|
end
|
|
47
34
|
end
|
|
48
35
|
|
|
49
|
-
def hint_id
|
|
50
|
-
return nil unless @hint_text.present?
|
|
51
|
-
|
|
52
|
-
build_id('hint')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def error_id
|
|
56
|
-
return nil unless has_errors?
|
|
57
|
-
|
|
58
|
-
build_id('error')
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def conditional_id
|
|
62
|
-
build_id('conditional')
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def supplemental_id
|
|
66
|
-
return nil unless @block_content.present?
|
|
67
|
-
|
|
68
|
-
build_id('supplemental')
|
|
69
|
-
end
|
|
70
|
-
|
|
71
36
|
def has_errors?
|
|
72
37
|
@builder.object.errors.any? &&
|
|
73
38
|
@builder.object.errors.messages.dig(@attribute_name).present?
|
|
74
39
|
end
|
|
75
40
|
|
|
76
|
-
def wrap_conditional(block)
|
|
77
|
-
content_tag('div', class: conditional_classes, id: conditional_id) do
|
|
78
|
-
capture { block.call }
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
41
|
def described_by(*ids)
|
|
83
42
|
ids.flatten.compact.join(' ').presence
|
|
84
43
|
end
|
|
85
44
|
|
|
86
|
-
private
|
|
87
|
-
|
|
88
45
|
# Builds the values used for HTML id attributes throughout the builder
|
|
89
46
|
#
|
|
90
47
|
# @param id_type [String] a description of the id's type, eg +hint+, +error+
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Builder
|
|
3
|
+
delegate :config, to: GOVUKDesignSystemFormBuilder
|
|
4
|
+
|
|
3
5
|
# Generates a input of type +text+
|
|
4
6
|
#
|
|
5
7
|
# @param attribute_name [Symbol] The name of the attribute
|
|
@@ -201,9 +203,12 @@ module GOVUKDesignSystemFormBuilder
|
|
|
201
203
|
#
|
|
202
204
|
# @param attribute_name [Symbol] The name of the attribute
|
|
203
205
|
# @param collection [Enumerable<Object>] Options to be added to the +select+ element
|
|
204
|
-
# @param value_method [Symbol] The method called against each member of the collection to provide the value
|
|
205
|
-
#
|
|
206
|
-
# @param
|
|
206
|
+
# @param value_method [Symbol, Proc] The method called against each member of the collection to provide the value.
|
|
207
|
+
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
|
208
|
+
# @param text_method [Symbol, Proc] The method called against each member of the collection to provide the label text.
|
|
209
|
+
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
|
210
|
+
# @param hint_method [Symbol, Proc] The method called against each member of the collection to provide the hint text.
|
|
211
|
+
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
|
207
212
|
# @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
|
|
208
213
|
# @param legend [Hash] options for configuring the legend
|
|
209
214
|
# @param inline [Boolean] controls whether the radio buttons are displayed inline or not
|
|
@@ -214,7 +219,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
214
219
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+, defaults to +h1+
|
|
215
220
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
216
221
|
#
|
|
217
|
-
# @example A collection of radio buttons for favourite colours
|
|
222
|
+
# @example A collection of radio buttons for favourite colours, labels capitalised via a proc
|
|
218
223
|
#
|
|
219
224
|
# @colours = [
|
|
220
225
|
# OpenStruct.new(id: 'red', name: 'Red', description: 'Roses are red'),
|
|
@@ -224,7 +229,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
224
229
|
# = f.govuk_collection_radio_buttons :favourite_colour,
|
|
225
230
|
# @colours,
|
|
226
231
|
# :id,
|
|
227
|
-
#
|
|
232
|
+
# ->(option) { option.name.upcase },
|
|
228
233
|
# :description,
|
|
229
234
|
# legend: { text: 'Pick your favourite colour', size: 'm' },
|
|
230
235
|
# hint_text: 'If you cannot find the exact match choose something close',
|
|
@@ -307,7 +312,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
307
312
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
308
313
|
# @example A custom divider
|
|
309
314
|
# = govuk_radio_divider 'Alternatively'
|
|
310
|
-
def govuk_radio_divider(text =
|
|
315
|
+
def govuk_radio_divider(text = config.default_radio_divider_text)
|
|
311
316
|
tag.div(text, class: %w(govuk-radios__divider))
|
|
312
317
|
end
|
|
313
318
|
|
|
@@ -316,8 +321,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
316
321
|
# @param attribute_name [Symbol] The name of the attribute
|
|
317
322
|
# @param collection [Enumerable<Object>] Options to be added to the +select+ element
|
|
318
323
|
# @param value_method [Symbol] The method called against each member of the collection to provide the value
|
|
319
|
-
# @param text_method [Symbol] The method called against each member of the collection to provide the text
|
|
320
|
-
# @param hint_method [Symbol] The method called against each member of the collection to provide the hint text
|
|
324
|
+
# @param text_method [Symbol] The method called against each member of the collection to provide the label text
|
|
325
|
+
# @param hint_method [Symbol, Proc] The method called against each member of the collection to provide the hint text.
|
|
326
|
+
# When a +Proc+ is provided it must take a single argument that is a single member of the collection
|
|
321
327
|
# @param hint_text [String] The content of the fieldset hint. No hint will be injected if left +nil+
|
|
322
328
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
|
323
329
|
# @param legend [Hash] options for configuring the legend
|
|
@@ -450,7 +456,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
450
456
|
# = f.govuk_submit "Proceed", prevent_double_click: true do
|
|
451
457
|
# = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
|
|
452
458
|
#
|
|
453
|
-
def govuk_submit(text =
|
|
459
|
+
def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, prevent_double_click: true, validate: false, &block)
|
|
454
460
|
Elements::Submit.new(self, text, warning: warning, secondary: secondary, prevent_double_click: prevent_double_click, validate: validate, &block).html
|
|
455
461
|
end
|
|
456
462
|
|
|
@@ -496,7 +502,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
496
502
|
# = f.govuk_error_summary 'Uh-oh, spaghettios'
|
|
497
503
|
#
|
|
498
504
|
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
|
|
499
|
-
def govuk_error_summary(title =
|
|
505
|
+
def govuk_error_summary(title = config.default_error_summary_title)
|
|
500
506
|
Elements::ErrorSummary.new(self, object_name, title).html
|
|
501
507
|
end
|
|
502
508
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Containers
|
|
3
|
-
class CheckBoxesFieldset <
|
|
3
|
+
class CheckBoxesFieldset < Base
|
|
4
|
+
include Traits::Error
|
|
5
|
+
include Traits::Hint
|
|
6
|
+
|
|
4
7
|
def initialize(builder, object_name, attribute_name, hint_text:, legend:, small:, &block)
|
|
5
8
|
super(builder, object_name, attribute_name, &block)
|
|
6
9
|
|
|
@@ -12,7 +15,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
12
15
|
|
|
13
16
|
def html
|
|
14
17
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
|
15
|
-
Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_element.error_id, hint_element.hint_id]).html do
|
|
18
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, legend: @legend, described_by: [error_element.error_id, hint_element.hint_id]).html do
|
|
16
19
|
safe_join(
|
|
17
20
|
[
|
|
18
21
|
hint_element.html,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Containers
|
|
3
|
-
class Fieldset <
|
|
4
|
-
|
|
3
|
+
class Fieldset < Base
|
|
4
|
+
include Traits::Localisation
|
|
5
|
+
|
|
5
6
|
LEGEND_SIZES = %w(xl l m s).freeze
|
|
6
7
|
|
|
7
|
-
def initialize(builder, legend: {}, described_by: nil)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@
|
|
8
|
+
def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, described_by: nil)
|
|
9
|
+
super(builder, object_name, attribute_name)
|
|
10
|
+
|
|
11
|
+
@legend = legend_defaults.merge(legend)
|
|
12
|
+
@described_by = described_by(described_by)
|
|
13
|
+
@attribute_name = attribute_name
|
|
11
14
|
end
|
|
12
15
|
|
|
13
16
|
def html
|
|
@@ -18,14 +21,26 @@ module GOVUKDesignSystemFormBuilder
|
|
|
18
21
|
|
|
19
22
|
private
|
|
20
23
|
|
|
24
|
+
def legend_defaults
|
|
25
|
+
{
|
|
26
|
+
text: nil,
|
|
27
|
+
tag: config.default_legend_tag,
|
|
28
|
+
size: config.default_legend_size
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
21
32
|
def build_legend
|
|
22
|
-
if
|
|
33
|
+
if legend_text.present?
|
|
23
34
|
content_tag('legend', class: legend_classes) do
|
|
24
|
-
tag.send(@legend.dig(:tag),
|
|
35
|
+
tag.send(@legend.dig(:tag), legend_text, class: legend_heading_classes)
|
|
25
36
|
end
|
|
26
37
|
end
|
|
27
38
|
end
|
|
28
39
|
|
|
40
|
+
def legend_text
|
|
41
|
+
[@legend.dig(:text), localised_text(:legend)].compact.first
|
|
42
|
+
end
|
|
43
|
+
|
|
29
44
|
def fieldset_classes
|
|
30
45
|
%w(govuk-fieldset)
|
|
31
46
|
end
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Containers
|
|
3
|
-
class RadioButtonsFieldset <
|
|
3
|
+
class RadioButtonsFieldset < Base
|
|
4
|
+
include Traits::Hint
|
|
5
|
+
include Traits::Error
|
|
6
|
+
|
|
4
7
|
def initialize(builder, object_name, attribute_name, hint_text:, legend:, inline:, small:, &block)
|
|
5
8
|
super(builder, object_name, attribute_name)
|
|
6
9
|
|
|
@@ -13,7 +16,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
13
16
|
|
|
14
17
|
def html
|
|
15
18
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
|
16
|
-
Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_element.error_id, hint_element.hint_id]).html do
|
|
19
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, legend: @legend, described_by: [error_element.error_id, hint_element.hint_id]).html do
|
|
17
20
|
safe_join(
|
|
18
21
|
[
|
|
19
22
|
hint_element.html,
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Containers
|
|
3
|
-
class Supplemental <
|
|
3
|
+
class Supplemental < Base
|
|
4
4
|
def initialize(builder, object_name, attribute_name, content)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@
|
|
8
|
-
@content = content
|
|
5
|
+
super(builder, object_name, attribute_name)
|
|
6
|
+
|
|
7
|
+
@content = content
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
def html
|
|
12
|
-
return nil
|
|
11
|
+
return nil if @content.blank?
|
|
13
12
|
|
|
14
13
|
content_tag('div', id: supplemental_id) do
|
|
15
14
|
@content
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
3
|
module CheckBoxes
|
|
4
|
-
class Collection <
|
|
4
|
+
class Collection < Base
|
|
5
|
+
include Traits::Error
|
|
6
|
+
include Traits::Hint
|
|
7
|
+
include Traits::Supplemental
|
|
8
|
+
|
|
5
9
|
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method: nil, hint_text:, legend:, small:, &block)
|
|
6
10
|
super(builder, object_name, attribute_name, &block)
|
|
7
11
|
|
|
@@ -16,7 +20,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
16
20
|
|
|
17
21
|
def html
|
|
18
22
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
|
19
|
-
Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
|
|
23
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
|
|
20
24
|
safe_join(
|
|
21
25
|
[
|
|
22
26
|
hint_element.html,
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
3
|
module CheckBoxes
|
|
4
|
-
class CollectionCheckBox <
|
|
4
|
+
class CollectionCheckBox < Base
|
|
5
|
+
include Traits::CollectionItem
|
|
6
|
+
include Traits::Hint
|
|
7
|
+
|
|
5
8
|
def initialize(builder, object_name, attribute_name, checkbox, hint_method = nil, link_errors: false)
|
|
6
9
|
super(builder, object_name, attribute_name)
|
|
10
|
+
|
|
7
11
|
@checkbox = checkbox
|
|
8
12
|
@item = checkbox.object
|
|
9
13
|
@value = checkbox.value
|
|
10
|
-
@hint_text = @item
|
|
14
|
+
@hint_text = retrieve(@item, hint_method)
|
|
11
15
|
@link_errors = link_errors
|
|
12
16
|
end
|
|
13
17
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
3
|
module CheckBoxes
|
|
4
|
-
class FieldsetCheckBox <
|
|
4
|
+
class FieldsetCheckBox < Base
|
|
5
|
+
include Traits::Hint
|
|
6
|
+
include Traits::Conditional
|
|
7
|
+
|
|
5
8
|
def initialize(builder, object_name, attribute_name, value, label:, hint_text:, link_errors:, multiple:, &block)
|
|
6
9
|
super(builder, object_name, attribute_name)
|
|
7
10
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
3
|
module CheckBoxes
|
|
4
|
-
class Hint <
|
|
4
|
+
class Hint < Base
|
|
5
|
+
include Traits::Hint
|
|
6
|
+
|
|
5
7
|
def initialize(builder, object_name, attribute_name, hint_text, value:)
|
|
6
8
|
super(builder, object_name, attribute_name)
|
|
7
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
3
|
module CheckBoxes
|
|
4
|
-
class Label <
|
|
4
|
+
class Label < Base
|
|
5
5
|
def initialize(builder, object_name, attribute_name, checkbox, value:, link_errors: true)
|
|
6
6
|
super(builder, object_name, attribute_name)
|
|
7
7
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
|
-
class Date <
|
|
3
|
+
class Date < Base
|
|
4
|
+
include Traits::Error
|
|
5
|
+
include Traits::Hint
|
|
6
|
+
include Traits::Supplemental
|
|
7
|
+
|
|
4
8
|
SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
|
|
5
9
|
|
|
6
10
|
def initialize(builder, object_name, attribute_name, legend:, hint_text:, date_of_birth: false, omit_day:, &block)
|
|
@@ -14,7 +18,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
14
18
|
|
|
15
19
|
def html
|
|
16
20
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
|
17
|
-
Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
|
|
21
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
|
|
18
22
|
safe_join(
|
|
19
23
|
[
|
|
20
24
|
hint_element.html,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
|
-
class ErrorMessage <
|
|
3
|
+
class ErrorMessage < Base
|
|
4
|
+
include Traits::Error
|
|
5
|
+
|
|
4
6
|
def initialize(builder, object_name, attribute_name)
|
|
5
7
|
super(builder, object_name, attribute_name)
|
|
6
8
|
end
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
|
-
class File <
|
|
3
|
+
class File < Base
|
|
4
|
+
include Traits::Error
|
|
5
|
+
include Traits::Hint
|
|
6
|
+
include Traits::Label
|
|
7
|
+
include Traits::Supplemental
|
|
8
|
+
|
|
4
9
|
def initialize(builder, object_name, attribute_name, hint_text:, label:, **extra_args, &block)
|
|
5
10
|
super(builder, object_name, attribute_name, &block)
|
|
6
11
|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
|
-
class Hint <
|
|
3
|
+
class Hint < Base
|
|
4
|
+
include Traits::Hint
|
|
5
|
+
include Traits::Localisation
|
|
6
|
+
|
|
4
7
|
def initialize(builder, object_name, attribute_name, text, value = nil, radio: false, checkbox: false)
|
|
5
8
|
super(builder, object_name, attribute_name)
|
|
6
9
|
|
|
7
10
|
@value = value
|
|
8
|
-
@hint_text = text
|
|
11
|
+
@hint_text = hint_text(text)
|
|
9
12
|
@radio_class = radio_class(radio)
|
|
10
13
|
@checkbox_class = checkbox_class(checkbox)
|
|
11
14
|
end
|
|
@@ -18,6 +21,13 @@ module GOVUKDesignSystemFormBuilder
|
|
|
18
21
|
|
|
19
22
|
private
|
|
20
23
|
|
|
24
|
+
def hint_text(supplied)
|
|
25
|
+
[
|
|
26
|
+
supplied.presence,
|
|
27
|
+
localised_text(:hint)
|
|
28
|
+
].compact.first
|
|
29
|
+
end
|
|
30
|
+
|
|
21
31
|
def hint_classes
|
|
22
32
|
%w(govuk-hint).push(@radio_class, @checkbox_class).compact
|
|
23
33
|
end
|
|
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Elements
|
|
3
3
|
module Inputs
|
|
4
4
|
class Email < Base
|
|
5
|
+
include Traits::Input
|
|
6
|
+
include Traits::Error
|
|
7
|
+
include Traits::Hint
|
|
8
|
+
include Traits::Label
|
|
9
|
+
include Traits::Supplemental
|
|
10
|
+
|
|
5
11
|
def builder_method
|
|
6
12
|
:email_field
|
|
7
13
|
end
|
|
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Elements
|
|
3
3
|
module Inputs
|
|
4
4
|
class Number < Base
|
|
5
|
+
include Traits::Input
|
|
6
|
+
include Traits::Error
|
|
7
|
+
include Traits::Hint
|
|
8
|
+
include Traits::Label
|
|
9
|
+
include Traits::Supplemental
|
|
10
|
+
|
|
5
11
|
def builder_method
|
|
6
12
|
:number_field
|
|
7
13
|
end
|
|
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Elements
|
|
3
3
|
module Inputs
|
|
4
4
|
class Phone < Base
|
|
5
|
+
include Traits::Input
|
|
6
|
+
include Traits::Error
|
|
7
|
+
include Traits::Hint
|
|
8
|
+
include Traits::Label
|
|
9
|
+
include Traits::Supplemental
|
|
10
|
+
|
|
5
11
|
def builder_method
|
|
6
12
|
:phone_field
|
|
7
13
|
end
|
|
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Elements
|
|
3
3
|
module Inputs
|
|
4
4
|
class Text < Base
|
|
5
|
+
include Traits::Input
|
|
6
|
+
include Traits::Error
|
|
7
|
+
include Traits::Hint
|
|
8
|
+
include Traits::Label
|
|
9
|
+
include Traits::Supplemental
|
|
10
|
+
|
|
5
11
|
def builder_method
|
|
6
12
|
:text_field
|
|
7
13
|
end
|
|
@@ -2,6 +2,12 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Elements
|
|
3
3
|
module Inputs
|
|
4
4
|
class URL < Base
|
|
5
|
+
include Traits::Input
|
|
6
|
+
include Traits::Error
|
|
7
|
+
include Traits::Hint
|
|
8
|
+
include Traits::Label
|
|
9
|
+
include Traits::Supplemental
|
|
10
|
+
|
|
5
11
|
def builder_method
|
|
6
12
|
:url_field
|
|
7
13
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
|
-
class Label <
|
|
3
|
+
class Label < Base
|
|
4
|
+
include Traits::Localisation
|
|
5
|
+
|
|
4
6
|
def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true)
|
|
5
7
|
super(builder, object_name, attribute_name)
|
|
6
8
|
|
|
@@ -37,12 +39,12 @@ module GOVUKDesignSystemFormBuilder
|
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def label_text(option_text, hidden)
|
|
40
|
-
text = [option_text, @value, @attribute_name.capitalize].compact.first
|
|
42
|
+
text = [option_text, @value, localised_text(:label), @attribute_name.capitalize].compact.first.to_s
|
|
41
43
|
|
|
42
44
|
if hidden
|
|
43
45
|
tag.span(text, class: %w(govuk-visually-hidden))
|
|
44
46
|
else
|
|
45
|
-
|
|
47
|
+
text
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
50
|
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
3
|
module Radios
|
|
4
|
-
class Collection <
|
|
4
|
+
class Collection < Base
|
|
5
|
+
include Traits::Error
|
|
6
|
+
include Traits::Hint
|
|
7
|
+
include Traits::Supplemental
|
|
8
|
+
|
|
5
9
|
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint_text:, legend:, inline:, small:, bold_labels:, &block)
|
|
6
10
|
super(builder, object_name, attribute_name, &block)
|
|
7
11
|
|
|
@@ -18,7 +22,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
18
22
|
|
|
19
23
|
def html
|
|
20
24
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
|
21
|
-
Containers::Fieldset.new(@builder, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
|
|
25
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, legend: @legend, described_by: [error_id, hint_id, supplemental_id]).html do
|
|
22
26
|
safe_join(
|
|
23
27
|
[
|
|
24
28
|
hint_element.html,
|
|
@@ -2,16 +2,20 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Elements
|
|
3
3
|
module Radios
|
|
4
4
|
class CollectionRadioButton < Base
|
|
5
|
+
include Traits::Hint
|
|
6
|
+
include Traits::CollectionItem
|
|
7
|
+
|
|
5
8
|
# @param link_errors [Boolean] used to control the id generated for radio buttons. The
|
|
6
9
|
# error summary requires that the id of the first radio is linked-to from the corresponding
|
|
7
10
|
# error message. As when the summary is built what happens later in the form is unknown, we
|
|
8
11
|
# need to control this to ensure the link is generated correctly
|
|
9
12
|
def initialize(builder, object_name, attribute_name, item, value_method:, text_method:, hint_method:, link_errors: false, bold_labels:)
|
|
10
13
|
super(builder, object_name, attribute_name)
|
|
14
|
+
|
|
11
15
|
@item = item
|
|
12
|
-
@value = item
|
|
13
|
-
@
|
|
14
|
-
@hint_text = item
|
|
16
|
+
@value = retrieve(item, value_method)
|
|
17
|
+
@label_text = retrieve(item, text_method)
|
|
18
|
+
@hint_text = retrieve(item, hint_method)
|
|
15
19
|
@link_errors = link_errors
|
|
16
20
|
@bold_labels = bold_labels
|
|
17
21
|
end
|
|
@@ -41,7 +45,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def label_element
|
|
44
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, text: @
|
|
48
|
+
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, text: @label_text, value: @value, radio: true, size: label_size, link_errors: @link_errors)
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
def label_size
|
|
@@ -2,6 +2,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Elements
|
|
3
3
|
module Radios
|
|
4
4
|
class FieldsetRadioButton < Base
|
|
5
|
+
include Traits::Hint
|
|
6
|
+
include Traits::Conditional
|
|
7
|
+
|
|
5
8
|
def initialize(builder, object_name, attribute_name, value, label:, hint_text:, link_errors:, &block)
|
|
6
9
|
super(builder, object_name, attribute_name)
|
|
7
10
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Elements
|
|
3
|
-
class Select <
|
|
3
|
+
class Select < Base
|
|
4
|
+
include Traits::Error
|
|
5
|
+
include Traits::Label
|
|
6
|
+
include Traits::Hint
|
|
7
|
+
include Traits::Supplemental
|
|
8
|
+
|
|
4
9
|
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, options: {}, html_options: {}, hint_text:, label:, &block)
|
|
5
10
|
super(builder, object_name, attribute_name, &block)
|
|
6
11
|
|