govuk_design_system_formbuilder 1.2.3 → 1.2.4
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/builder.rb +3 -0
- data/lib/govuk_design_system_formbuilder/containers/character_count.rb +8 -7
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +8 -1
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +9 -1
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +21 -11
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +9 -1
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +8 -1
- data/lib/govuk_design_system_formbuilder/containers/supplemental.rb +1 -3
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +9 -1
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +5 -1
- data/lib/govuk_design_system_formbuilder/elements/date.rb +37 -31
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +10 -10
- data/lib/govuk_design_system_formbuilder/elements/label.rb +19 -15
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +9 -1
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +11 -1
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +6 -2
- data/lib/govuk_design_system_formbuilder/elements/select.rb +10 -6
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +3 -3
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +23 -18
- data/lib/govuk_design_system_formbuilder/traits/input.rb +6 -6
- data/lib/govuk_design_system_formbuilder/traits/label.rb +2 -2
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d0ec456d05c0f92a86c39b688f0ac2a498160f473002f2fb4004567f4b17496
|
4
|
+
data.tar.gz: 0aa054ef3feb33eaf5b402aaea08ab2942e9b9be6708f04de41c1255e455dc86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a79e3ac6187857d917f7eb253abfbb414b8ed44a3a4488a29f82052ca234daeba9f1926a0df12697544fa266420ebe8eba8ab26840fe8d371b713d82c2df312
|
7
|
+
data.tar.gz: 1334ddb5eb6a36dfbcd5b8f91b50548ecfac38481682e683aec5071d2f91b7577f3cadd532c8dd8c1b1c5dba34fa837479ef55d5f63669b15756159e5b9fb5aa
|
@@ -312,7 +312,10 @@ module GOVUKDesignSystemFormBuilder
|
|
312
312
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
313
313
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
314
314
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
315
|
+
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
316
|
+
# @param html_options [Hash] HTML Options hash passed through to Rails' +collection_select+ helper
|
315
317
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
318
|
+
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
316
319
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
317
320
|
#
|
318
321
|
# @example A select box with hint
|
@@ -14,17 +14,18 @@ module GOVUKDesignSystemFormBuilder
|
|
14
14
|
def html
|
15
15
|
return yield unless limit?
|
16
16
|
|
17
|
-
content_tag(
|
18
|
-
'div',
|
19
|
-
class: %(#{brand}-character-count),
|
20
|
-
data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
|
21
|
-
) do
|
22
|
-
yield
|
23
|
-
end
|
17
|
+
content_tag('div', **character_count_options) { yield }
|
24
18
|
end
|
25
19
|
|
26
20
|
private
|
27
21
|
|
22
|
+
def character_count_options
|
23
|
+
{
|
24
|
+
class: %(#{brand}-character-count),
|
25
|
+
data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
28
29
|
def limit
|
29
30
|
if @max_words
|
30
31
|
{ maxwords: @max_words }
|
@@ -10,13 +10,20 @@ module GOVUKDesignSystemFormBuilder
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def html
|
13
|
-
content_tag('div',
|
13
|
+
content_tag('div', **check_boxes_options) do
|
14
14
|
yield
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
+
def check_boxes_options
|
21
|
+
{
|
22
|
+
class: check_boxes_classes,
|
23
|
+
data: { module: %(#{brand}-checkboxes) }
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
20
27
|
def check_boxes_classes
|
21
28
|
%w(checkboxes).prefix(brand).tap do |c|
|
22
29
|
c.push(%(#{brand}-checkboxes--small)) if @small
|
@@ -17,7 +17,7 @@ module GOVUKDesignSystemFormBuilder
|
|
17
17
|
|
18
18
|
def html
|
19
19
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
20
|
-
Containers::Fieldset.new(@builder, @object_name, @attribute_name,
|
20
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
21
21
|
safe_join([hint_element, error_element, checkboxes])
|
22
22
|
end
|
23
23
|
end
|
@@ -25,6 +25,14 @@ module GOVUKDesignSystemFormBuilder
|
|
25
25
|
|
26
26
|
private
|
27
27
|
|
28
|
+
def fieldset_options
|
29
|
+
{
|
30
|
+
legend: @legend,
|
31
|
+
caption: @caption,
|
32
|
+
described_by: [error_element.error_id, hint_element.hint_id]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
28
36
|
def checkboxes
|
29
37
|
Containers::CheckBoxes.new(@builder, small: @small, classes: @classes).html do
|
30
38
|
@block_content
|
@@ -26,18 +26,29 @@ module GOVUKDesignSystemFormBuilder
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def html
|
29
|
-
content_tag('fieldset',
|
30
|
-
safe_join([
|
29
|
+
content_tag('fieldset', **fieldset_options) do
|
30
|
+
safe_join([legend, (@block_content || yield)])
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
-
def
|
37
|
-
|
36
|
+
def fieldset_options
|
37
|
+
{
|
38
|
+
class: fieldset_classes,
|
39
|
+
aria: { describedby: @described_by }
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def fieldset_classes
|
44
|
+
%w(fieldset).prefix(brand)
|
38
45
|
end
|
39
46
|
|
40
47
|
def legend
|
48
|
+
@legend_raw || legend_content
|
49
|
+
end
|
50
|
+
|
51
|
+
def legend_content
|
41
52
|
if legend_text.present?
|
42
53
|
content_tag('legend', class: legend_classes) do
|
43
54
|
content_tag(@legend_options.dig(:tag), class: legend_heading_classes) do
|
@@ -48,18 +59,17 @@ module GOVUKDesignSystemFormBuilder
|
|
48
59
|
end
|
49
60
|
|
50
61
|
def legend_text
|
51
|
-
|
62
|
+
@legend_options.dig(:text) || localised_text(:legend)
|
52
63
|
end
|
53
64
|
|
54
|
-
def
|
55
|
-
|
65
|
+
def legend_size
|
66
|
+
@legend_options.dig(:size).tap do |size|
|
67
|
+
fail "invalid size '#{size}', must be #{LEGEND_SIZES.join(', ')}" unless size.in?(LEGEND_SIZES)
|
68
|
+
end
|
56
69
|
end
|
57
70
|
|
58
71
|
def legend_classes
|
59
|
-
|
60
|
-
fail "invalid size '#{size}', must be #{LEGEND_SIZES.join(', ')}" unless size.in?(LEGEND_SIZES)
|
61
|
-
|
62
|
-
[%(fieldset__legend), %(fieldset__legend--#{size})].prefix(brand).tap do |classes|
|
72
|
+
[%(fieldset__legend), %(fieldset__legend--#{legend_size})].prefix(brand).tap do |classes|
|
63
73
|
classes.push(%(#{brand}-visually-hidden)) if @legend_options.dig(:hidden)
|
64
74
|
end
|
65
75
|
end
|
@@ -18,7 +18,7 @@ module GOVUKDesignSystemFormBuilder
|
|
18
18
|
|
19
19
|
def html
|
20
20
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
21
|
-
Containers::Fieldset.new(@builder, @object_name, @attribute_name,
|
21
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
22
22
|
safe_join([hint_element, error_element, radios])
|
23
23
|
end
|
24
24
|
end
|
@@ -26,6 +26,14 @@ module GOVUKDesignSystemFormBuilder
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
+
def fieldset_options
|
30
|
+
{
|
31
|
+
legend: @legend,
|
32
|
+
caption: @caption,
|
33
|
+
described_by: [error_element.error_id, hint_element.hint_id]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
29
37
|
def radios
|
30
38
|
Containers::Radios.new(@builder, inline: @inline, small: @small, classes: @classes).html do
|
31
39
|
@block_content
|
@@ -13,13 +13,20 @@ module GOVUKDesignSystemFormBuilder
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def html
|
16
|
-
content_tag('div',
|
16
|
+
content_tag('div', **radios_options) do
|
17
17
|
yield
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
+
def radios_options
|
24
|
+
{
|
25
|
+
class: radios_classes,
|
26
|
+
data: { module: %(#{brand}-radios) }
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
23
30
|
def radios_classes
|
24
31
|
%w(radios).prefix(brand).tap do |c|
|
25
32
|
c.push(%(#{brand}-radios--inline)) if @inline
|
@@ -22,7 +22,7 @@ module GOVUKDesignSystemFormBuilder
|
|
22
22
|
|
23
23
|
def html
|
24
24
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
25
|
-
Containers::Fieldset.new(@builder, @object_name, @attribute_name,
|
25
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
26
26
|
safe_join([supplemental_content, hint_element, error_element, check_boxes])
|
27
27
|
end
|
28
28
|
end
|
@@ -30,6 +30,14 @@ module GOVUKDesignSystemFormBuilder
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
+
def fieldset_options
|
34
|
+
{
|
35
|
+
legend: @legend,
|
36
|
+
caption: @caption,
|
37
|
+
described_by: [error_id, hint_id, supplemental_id]
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
33
41
|
def check_boxes
|
34
42
|
Containers::CheckBoxes.new(@builder, small: @small, classes: @classes).html do
|
35
43
|
collection
|
@@ -50,7 +50,11 @@ module GOVUKDesignSystemFormBuilder
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def label_element
|
53
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name,
|
53
|
+
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def label_options
|
57
|
+
{ checkbox: true, value: @value, link_errors: @link_errors }
|
54
58
|
end
|
55
59
|
|
56
60
|
def hint_element
|
@@ -21,7 +21,7 @@ module GOVUKDesignSystemFormBuilder
|
|
21
21
|
|
22
22
|
def html
|
23
23
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
24
|
-
Containers::Fieldset.new(@builder, @object_name, @attribute_name,
|
24
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
25
25
|
safe_join([supplemental_content, hint_element, error_element, date])
|
26
26
|
end
|
27
27
|
end
|
@@ -29,6 +29,10 @@ module GOVUKDesignSystemFormBuilder
|
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
+
def fieldset_options
|
33
|
+
{ legend: @legend, caption: @caption, described_by: [error_id, hint_id, supplemental_id] }
|
34
|
+
end
|
35
|
+
|
32
36
|
def date
|
33
37
|
content_tag('div', class: %(#{brand}-date-input)) do
|
34
38
|
safe_join([day, month, year])
|
@@ -42,61 +46,63 @@ module GOVUKDesignSystemFormBuilder
|
|
42
46
|
def day
|
43
47
|
return nil if omit_day?
|
44
48
|
|
45
|
-
|
49
|
+
date_part(:day, width: 2, link_errors: true)
|
46
50
|
end
|
47
51
|
|
48
52
|
def month
|
49
|
-
|
53
|
+
date_part(:month, width: 2, link_errors: omit_day?)
|
50
54
|
end
|
51
55
|
|
52
56
|
def year
|
53
|
-
|
57
|
+
date_part(:year, width: 4)
|
54
58
|
end
|
55
59
|
|
56
|
-
def
|
60
|
+
def date_part(segment, width:, link_errors: false)
|
57
61
|
value = @builder.object.try(@attribute_name).try(segment)
|
58
62
|
|
59
63
|
content_tag('div', class: %w(date-input__item).prefix(brand)) do
|
60
64
|
content_tag('div', class: %w(form-group).prefix(brand)) do
|
61
|
-
safe_join(
|
62
|
-
[
|
63
|
-
tag.label(
|
64
|
-
segment.capitalize,
|
65
|
-
class: date_part_label_classes,
|
66
|
-
for: date_part_attribute_id(segment, link_errors)
|
67
|
-
),
|
68
|
-
|
69
|
-
tag.input(
|
70
|
-
id: date_part_attribute_id(segment, link_errors),
|
71
|
-
class: date_part_input_classes(width),
|
72
|
-
name: date_part_attribute_name(segment),
|
73
|
-
type: 'text',
|
74
|
-
pattern: '[0-9]*',
|
75
|
-
inputmode: 'numeric',
|
76
|
-
value: value,
|
77
|
-
autocomplete: date_of_birth_autocomplete_value(segment)
|
78
|
-
)
|
79
|
-
]
|
80
|
-
)
|
65
|
+
safe_join([label(segment, link_errors), input(segment, link_errors, width, value)])
|
81
66
|
end
|
82
67
|
end
|
83
68
|
end
|
84
69
|
|
85
|
-
def
|
70
|
+
def label(segment, link_errors)
|
71
|
+
tag.label(
|
72
|
+
segment.capitalize,
|
73
|
+
class: label_classes,
|
74
|
+
for: input_id(segment, link_errors)
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def input(segment, link_errors, width, value)
|
79
|
+
tag.input(
|
80
|
+
id: input_id(segment, link_errors),
|
81
|
+
class: input_classes(width),
|
82
|
+
name: input_name(segment),
|
83
|
+
type: 'text',
|
84
|
+
pattern: '[0-9]*',
|
85
|
+
inputmode: 'numeric',
|
86
|
+
value: value,
|
87
|
+
autocomplete: date_of_birth_autocomplete_value(segment)
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
def input_classes(width)
|
86
92
|
%w(input date-input__input).prefix(brand).tap do |classes|
|
87
93
|
classes.push(%(#{brand}-input--width-#{width}))
|
88
94
|
classes.push(%(#{brand}-input--error)) if has_errors?
|
89
95
|
end
|
90
96
|
end
|
91
97
|
|
92
|
-
def
|
98
|
+
def label_classes
|
93
99
|
%w(label date-input__label).prefix(brand)
|
94
100
|
end
|
95
101
|
|
96
102
|
# if the field has errors we want the govuk_error_summary to
|
97
103
|
# be able to link to the day field. Otherwise, generate IDs
|
98
104
|
# in the normal fashion
|
99
|
-
def
|
105
|
+
def input_id(segment, link_errors)
|
100
106
|
if has_errors? && link_errors
|
101
107
|
field_id(link_errors: link_errors)
|
102
108
|
else
|
@@ -104,11 +110,11 @@ module GOVUKDesignSystemFormBuilder
|
|
104
110
|
end
|
105
111
|
end
|
106
112
|
|
107
|
-
def
|
113
|
+
def input_name(segment)
|
108
114
|
format(
|
109
|
-
"%<object_name>s[%<
|
115
|
+
"%<object_name>s[%<input_name>s(%<segment>s)]",
|
110
116
|
object_name: @object_name,
|
111
|
-
|
117
|
+
input_name: @attribute_name,
|
112
118
|
segment: SEGMENTS.fetch(segment)
|
113
119
|
)
|
114
120
|
end
|
@@ -9,10 +9,10 @@ module GOVUKDesignSystemFormBuilder
|
|
9
9
|
def initialize(builder, object_name, attribute_name, text, value = nil, radio: false, checkbox: false)
|
10
10
|
super(builder, object_name, attribute_name)
|
11
11
|
|
12
|
-
@value
|
13
|
-
@hint_text
|
14
|
-
@
|
15
|
-
@
|
12
|
+
@value = value
|
13
|
+
@hint_text = hint_text(text)
|
14
|
+
@radio = radio
|
15
|
+
@checkbox = checkbox
|
16
16
|
end
|
17
17
|
|
18
18
|
def html
|
@@ -24,19 +24,19 @@ module GOVUKDesignSystemFormBuilder
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def hint_text(supplied)
|
27
|
-
|
27
|
+
supplied.presence || localised_text(:hint)
|
28
28
|
end
|
29
29
|
|
30
30
|
def hint_classes
|
31
|
-
%w(hint).prefix(brand).push(
|
31
|
+
%w(hint).prefix(brand).push(radio_class, checkbox_class).compact
|
32
32
|
end
|
33
33
|
|
34
|
-
def radio_class
|
35
|
-
radio ? %(#{brand}-radios__hint) : nil
|
34
|
+
def radio_class
|
35
|
+
@radio ? %(#{brand}-radios__hint) : nil
|
36
36
|
end
|
37
37
|
|
38
|
-
def checkbox_class
|
39
|
-
checkbox ? %(#{brand}-checkboxes__hint) : nil
|
38
|
+
def checkbox_class
|
39
|
+
@checkbox ? %(#{brand}-checkboxes__hint) : nil
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -14,14 +14,14 @@ module GOVUKDesignSystemFormBuilder
|
|
14
14
|
if content
|
15
15
|
@content = content.call
|
16
16
|
else
|
17
|
-
@value
|
18
|
-
@text
|
19
|
-
@size_class
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@tag
|
23
|
-
@link_errors
|
24
|
-
@caption
|
17
|
+
@value = value # used by field_id
|
18
|
+
@text = label_text(text, hidden)
|
19
|
+
@size_class = label_size_class(size)
|
20
|
+
@radio = radio
|
21
|
+
@checkbox = checkbox
|
22
|
+
@tag = tag
|
23
|
+
@link_errors = link_errors
|
24
|
+
@caption = caption
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -38,7 +38,7 @@ module GOVUKDesignSystemFormBuilder
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def label
|
41
|
-
@builder.label(@attribute_name, label_options) do
|
41
|
+
@builder.label(@attribute_name, **label_options) do
|
42
42
|
@content || safe_join([caption, @text])
|
43
43
|
end
|
44
44
|
end
|
@@ -57,20 +57,24 @@ module GOVUKDesignSystemFormBuilder
|
|
57
57
|
{
|
58
58
|
value: @value,
|
59
59
|
for: field_id(link_errors: @link_errors),
|
60
|
-
class: %w(label).prefix(brand).push(@size_class, @weight_class,
|
60
|
+
class: %w(label).prefix(brand).push(@size_class, @weight_class, radio_class, checkbox_class).compact
|
61
61
|
}
|
62
62
|
end
|
63
63
|
|
64
64
|
def caption
|
65
|
-
caption_element.html unless [@
|
65
|
+
caption_element.html unless [@radio, @checkbox].any?
|
66
66
|
end
|
67
67
|
|
68
|
-
def radio_class
|
69
|
-
|
68
|
+
def radio_class
|
69
|
+
return nil unless @radio
|
70
|
+
|
71
|
+
%(#{brand}-radios__label)
|
70
72
|
end
|
71
73
|
|
72
|
-
def checkbox_class
|
73
|
-
|
74
|
+
def checkbox_class
|
75
|
+
return nil unless @checkbox
|
76
|
+
|
77
|
+
%(#{brand}-checkboxes__label)
|
74
78
|
end
|
75
79
|
|
76
80
|
def label_size_class(size)
|
@@ -24,7 +24,7 @@ module GOVUKDesignSystemFormBuilder
|
|
24
24
|
|
25
25
|
def html
|
26
26
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
27
|
-
Containers::Fieldset.new(@builder, @object_name, @attribute_name,
|
27
|
+
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
28
28
|
safe_join([supplemental_content, hint_element, error_element, radios])
|
29
29
|
end
|
30
30
|
end
|
@@ -32,6 +32,14 @@ module GOVUKDesignSystemFormBuilder
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
+
def fieldset_options
|
36
|
+
{
|
37
|
+
legend: @legend,
|
38
|
+
caption: @caption,
|
39
|
+
described_by: [error_id, hint_id, supplemental_id]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
35
43
|
def radios
|
36
44
|
Containers::Radios.new(@builder, inline: @inline, small: @small, classes: @classes).html do
|
37
45
|
safe_join(collection)
|
@@ -47,7 +47,17 @@ module GOVUKDesignSystemFormBuilder
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def label_element
|
50
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name,
|
50
|
+
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def label_options
|
54
|
+
{
|
55
|
+
text: @label_text,
|
56
|
+
value: @value,
|
57
|
+
radio: true,
|
58
|
+
size: label_size,
|
59
|
+
link_errors: @link_errors
|
60
|
+
}
|
51
61
|
end
|
52
62
|
|
53
63
|
def label_size
|
@@ -35,7 +35,11 @@ module GOVUKDesignSystemFormBuilder
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def label_element
|
38
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name,
|
38
|
+
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def label_options
|
42
|
+
{ radio: true, value: @value, link_errors: @link_errors }
|
39
43
|
end
|
40
44
|
|
41
45
|
def hint_element
|
@@ -43,7 +47,7 @@ module GOVUKDesignSystemFormBuilder
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def input
|
46
|
-
@builder.radio_button(@attribute_name, @value, input_options)
|
50
|
+
@builder.radio_button(@attribute_name, @value, **input_options)
|
47
51
|
end
|
48
52
|
|
49
53
|
def input_options
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Elements
|
3
3
|
class Select < Base
|
4
|
-
using PrefixableArray
|
5
|
-
|
6
4
|
include Traits::Error
|
7
5
|
include Traits::Label
|
8
6
|
include Traits::Hint
|
@@ -30,7 +28,7 @@ module GOVUKDesignSystemFormBuilder
|
|
30
28
|
private
|
31
29
|
|
32
30
|
def select
|
33
|
-
@builder.collection_select(@attribute_name, @collection, @value_method, @text_method, @options, select_options)
|
31
|
+
@builder.collection_select(@attribute_name, @collection, @value_method, @text_method, @options, **select_options)
|
34
32
|
end
|
35
33
|
|
36
34
|
def select_options
|
@@ -42,9 +40,15 @@ module GOVUKDesignSystemFormBuilder
|
|
42
40
|
end
|
43
41
|
|
44
42
|
def select_classes
|
45
|
-
%
|
46
|
-
|
47
|
-
|
43
|
+
[%(#{brand}-select), select_error_class, select_custom_classes].flatten.compact
|
44
|
+
end
|
45
|
+
|
46
|
+
def select_error_class
|
47
|
+
%(#{brand}-select--error) if has_errors?
|
48
|
+
end
|
49
|
+
|
50
|
+
def select_custom_classes
|
51
|
+
@html_options.dig(:class)
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -30,7 +30,7 @@ module GOVUKDesignSystemFormBuilder
|
|
30
30
|
def submit_classes
|
31
31
|
%w(button)
|
32
32
|
.prefix(brand)
|
33
|
-
.push(warning_class, secondary_class, disabled_class,
|
33
|
+
.push(warning_class, secondary_class, disabled_class, padding_class, @classes)
|
34
34
|
.compact
|
35
35
|
end
|
36
36
|
|
@@ -53,8 +53,8 @@ module GOVUKDesignSystemFormBuilder
|
|
53
53
|
%(#{brand}-button--secondary) if @secondary
|
54
54
|
end
|
55
55
|
|
56
|
-
def padding_class
|
57
|
-
%(#{brand}-!-margin-right-1) if
|
56
|
+
def padding_class
|
57
|
+
%(#{brand}-!-margin-right-1) if @block_content
|
58
58
|
end
|
59
59
|
|
60
60
|
def disabled_class
|
@@ -11,18 +11,18 @@ module GOVUKDesignSystemFormBuilder
|
|
11
11
|
def initialize(builder, object_name, attribute_name, hint_text:, label:, caption:, rows:, max_words:, max_chars:, threshold:, **kwargs, &block)
|
12
12
|
super(builder, object_name, attribute_name, &block)
|
13
13
|
|
14
|
-
@label
|
15
|
-
@caption
|
16
|
-
@hint_text
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@
|
14
|
+
@label = label
|
15
|
+
@caption = caption
|
16
|
+
@hint_text = hint_text
|
17
|
+
@max_words = max_words
|
18
|
+
@max_chars = max_chars
|
19
|
+
@threshold = threshold
|
20
|
+
@rows = rows
|
21
|
+
@html_attributes = kwargs
|
22
22
|
end
|
23
23
|
|
24
24
|
def html
|
25
|
-
Containers::CharacterCount.new(@builder,
|
25
|
+
Containers::CharacterCount.new(@builder, **character_count_options).html do
|
26
26
|
Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
|
27
27
|
safe_join([label_element, supplemental_content, hint_element, error_element, text_area, limit_description])
|
28
28
|
end
|
@@ -31,8 +31,12 @@ module GOVUKDesignSystemFormBuilder
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
+
def character_count_options
|
35
|
+
{ max_words: @max_words, max_chars: @max_chars, threshold: @threshold }
|
36
|
+
end
|
37
|
+
|
34
38
|
def text_area
|
35
|
-
@builder.text_area(@attribute_name, **text_area_options, **@
|
39
|
+
@builder.text_area(@attribute_name, **text_area_options, **@html_attributes)
|
36
40
|
end
|
37
41
|
|
38
42
|
def text_area_classes
|
@@ -46,6 +50,7 @@ module GOVUKDesignSystemFormBuilder
|
|
46
50
|
{
|
47
51
|
id: field_id(link_errors: true),
|
48
52
|
class: text_area_classes,
|
53
|
+
rows: @rows,
|
49
54
|
aria: { describedby: described_by(hint_id, error_id, supplemental_id, limit_description_id) },
|
50
55
|
}
|
51
56
|
end
|
@@ -59,9 +64,17 @@ module GOVUKDesignSystemFormBuilder
|
|
59
64
|
end
|
60
65
|
|
61
66
|
def limit?
|
67
|
+
limit_quantity.present?
|
68
|
+
end
|
69
|
+
|
70
|
+
def limit_quantity
|
62
71
|
@max_words || @max_chars
|
63
72
|
end
|
64
73
|
|
74
|
+
def limit_type
|
75
|
+
@max_words.present? ? 'words' : 'characters'
|
76
|
+
end
|
77
|
+
|
65
78
|
def limit_description
|
66
79
|
return nil unless limit?
|
67
80
|
|
@@ -74,14 +87,6 @@ module GOVUKDesignSystemFormBuilder
|
|
74
87
|
%w(hint character-count__message).prefix(brand)
|
75
88
|
end
|
76
89
|
|
77
|
-
def limit_quantity
|
78
|
-
@max_words || @max_chars
|
79
|
-
end
|
80
|
-
|
81
|
-
def limit_type
|
82
|
-
@max_words.present? ? 'words' : 'characters'
|
83
|
-
end
|
84
|
-
|
85
90
|
def limit_description_id
|
86
91
|
return nil unless limit?
|
87
92
|
|
@@ -4,11 +4,11 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
def initialize(builder, object_name, attribute_name, hint_text:, label:, caption:, width:, **kwargs, &block)
|
5
5
|
super(builder, object_name, attribute_name, &block)
|
6
6
|
|
7
|
-
@width
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
7
|
+
@width = width
|
8
|
+
@label = label
|
9
|
+
@caption = caption
|
10
|
+
@hint_text = hint_text
|
11
|
+
@html_attributes = kwargs
|
12
12
|
end
|
13
13
|
|
14
14
|
def html
|
@@ -20,7 +20,7 @@ module GOVUKDesignSystemFormBuilder
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def input
|
23
|
-
@builder.send(builder_method, @attribute_name, **input_options
|
23
|
+
@builder.send(builder_method, @attribute_name, **input_options, **@html_attributes)
|
24
24
|
end
|
25
25
|
|
26
26
|
def input_options
|
@@ -4,10 +4,10 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
private
|
5
5
|
|
6
6
|
def label_element
|
7
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, caption: @caption, **
|
7
|
+
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, caption: @caption, **label_content)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def label_content
|
11
11
|
case @label
|
12
12
|
when Hash
|
13
13
|
@label
|
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.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.16.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.16.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,14 +176,14 @@ dependencies:
|
|
176
176
|
requirements:
|
177
177
|
- - "~>"
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version: 3.
|
179
|
+
version: 3.20.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.
|
186
|
+
version: 3.20.0
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: rubypants
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -204,14 +204,14 @@ dependencies:
|
|
204
204
|
requirements:
|
205
205
|
- - "~>"
|
206
206
|
- !ruby/object:Gem::Version
|
207
|
-
version: 2.
|
207
|
+
version: 2.4.0
|
208
208
|
type: :development
|
209
209
|
prerelease: false
|
210
210
|
version_requirements: !ruby/object:Gem::Requirement
|
211
211
|
requirements:
|
212
212
|
- - "~>"
|
213
213
|
- !ruby/object:Gem::Version
|
214
|
-
version: 2.
|
214
|
+
version: 2.4.0
|
215
215
|
- !ruby/object:Gem::Dependency
|
216
216
|
name: sass
|
217
217
|
requirement: !ruby/object:Gem::Requirement
|