govuk_design_system_formbuilder 1.2.7 → 2.0.0b1
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 +147 -72
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +9 -9
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +4 -3
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +10 -10
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +12 -12
- 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 +7 -3
- data/lib/govuk_design_system_formbuilder/elements/date.rb +8 -8
- data/lib/govuk_design_system_formbuilder/elements/file.rb +7 -7
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +35 -8
- data/lib/govuk_design_system_formbuilder/elements/label.rb +6 -2
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +14 -14
- data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +9 -1
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +13 -5
- data/lib/govuk_design_system_formbuilder/elements/select.rb +11 -11
- data/lib/govuk_design_system_formbuilder/elements/text_area.rb +11 -11
- data/lib/govuk_design_system_formbuilder/traits/collection_item.rb +1 -1
- data/lib/govuk_design_system_formbuilder/traits/hint.rb +15 -2
- data/lib/govuk_design_system_formbuilder/traits/input.rb +8 -8
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +4 -4
@@ -4,20 +4,20 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
include Traits::Error
|
5
5
|
include Traits::Hint
|
6
6
|
|
7
|
-
def initialize(builder, object_name, attribute_name,
|
7
|
+
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, small:, classes:, form_group:, &block)
|
8
8
|
super(builder, object_name, attribute_name, &block)
|
9
9
|
|
10
|
-
@legend
|
11
|
-
@caption
|
12
|
-
@
|
13
|
-
@small
|
14
|
-
@classes
|
15
|
-
@
|
16
|
-
@block_content
|
10
|
+
@legend = legend
|
11
|
+
@caption = caption
|
12
|
+
@hint = hint
|
13
|
+
@small = small
|
14
|
+
@classes = classes
|
15
|
+
@form_group = form_group
|
16
|
+
@block_content = capture { block.call }
|
17
17
|
end
|
18
18
|
|
19
19
|
def html
|
20
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name,
|
20
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
21
21
|
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
22
22
|
safe_join([hint_element, error_element, checkboxes])
|
23
23
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
2
2
|
module Containers
|
3
3
|
class FormGroup < Base
|
4
|
-
def initialize(builder, object_name, attribute_name, classes: nil)
|
4
|
+
def initialize(builder, object_name, attribute_name, classes: nil, **kwargs)
|
5
5
|
super(builder, object_name, attribute_name)
|
6
6
|
|
7
|
-
@classes
|
7
|
+
@classes = classes
|
8
|
+
@extra_options = kwargs
|
8
9
|
end
|
9
10
|
|
10
11
|
def html
|
11
|
-
tag.div(class: classes) { yield }
|
12
|
+
tag.div(class: classes, **@extra_options) { yield }
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
@@ -4,21 +4,21 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
include Traits::Hint
|
5
5
|
include Traits::Error
|
6
6
|
|
7
|
-
def initialize(builder, object_name, attribute_name,
|
7
|
+
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, inline:, small:, classes:, form_group:, &block)
|
8
8
|
super(builder, object_name, attribute_name)
|
9
9
|
|
10
|
-
@inline
|
11
|
-
@small
|
12
|
-
@legend
|
13
|
-
@caption
|
14
|
-
@
|
15
|
-
@classes
|
16
|
-
@
|
17
|
-
@block_content
|
10
|
+
@inline = inline
|
11
|
+
@small = small
|
12
|
+
@legend = legend
|
13
|
+
@caption = caption
|
14
|
+
@hint = hint
|
15
|
+
@classes = classes
|
16
|
+
@form_group = form_group
|
17
|
+
@block_content = capture { block.call }
|
18
18
|
end
|
19
19
|
|
20
20
|
def html
|
21
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name,
|
21
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
22
22
|
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
23
23
|
safe_join([hint_element, error_element, radios])
|
24
24
|
end
|
@@ -6,23 +6,23 @@ module GOVUKDesignSystemFormBuilder
|
|
6
6
|
include Traits::Hint
|
7
7
|
include Traits::Supplemental
|
8
8
|
|
9
|
-
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method: nil,
|
9
|
+
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method: nil, hint:, legend:, caption:, small:, classes:, form_group:, &block)
|
10
10
|
super(builder, object_name, attribute_name, &block)
|
11
11
|
|
12
|
-
@collection
|
13
|
-
@value_method
|
14
|
-
@text_method
|
15
|
-
@hint_method
|
16
|
-
@small
|
17
|
-
@legend
|
18
|
-
@caption
|
19
|
-
@
|
20
|
-
@classes
|
21
|
-
@
|
12
|
+
@collection = collection
|
13
|
+
@value_method = value_method
|
14
|
+
@text_method = text_method
|
15
|
+
@hint_method = hint_method
|
16
|
+
@small = small
|
17
|
+
@legend = legend
|
18
|
+
@caption = caption
|
19
|
+
@hint = hint
|
20
|
+
@classes = classes
|
21
|
+
@form_group = form_group
|
22
22
|
end
|
23
23
|
|
24
24
|
def html
|
25
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name,
|
25
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
26
26
|
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
27
27
|
safe_join([supplemental_content, hint_element, error_element, check_boxes])
|
28
28
|
end
|
@@ -11,7 +11,7 @@ module GOVUKDesignSystemFormBuilder
|
|
11
11
|
@checkbox = checkbox
|
12
12
|
@item = checkbox.object
|
13
13
|
@value = checkbox.value
|
14
|
-
@
|
14
|
+
@hint = { text: retrieve(@item, hint_method) }
|
15
15
|
@link_errors = link_errors
|
16
16
|
end
|
17
17
|
|
@@ -40,7 +40,11 @@ module GOVUKDesignSystemFormBuilder
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def hint_element
|
43
|
-
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name,
|
43
|
+
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
|
44
|
+
end
|
45
|
+
|
46
|
+
def hint_options
|
47
|
+
{ value: @value, checkbox: true }
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
@@ -8,12 +8,12 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
include Traits::Hint
|
9
9
|
include Traits::Conditional
|
10
10
|
|
11
|
-
def initialize(builder, object_name, attribute_name, value, label:,
|
11
|
+
def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, multiple:, &block)
|
12
12
|
super(builder, object_name, attribute_name)
|
13
13
|
|
14
14
|
@value = value
|
15
15
|
@label = label
|
16
|
-
@
|
16
|
+
@hint = hint
|
17
17
|
@multiple = multiple
|
18
18
|
@link_errors = link_errors
|
19
19
|
|
@@ -62,7 +62,11 @@ module GOVUKDesignSystemFormBuilder
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def hint_element
|
65
|
-
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name,
|
65
|
+
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
|
66
|
+
end
|
67
|
+
|
68
|
+
def hint_options
|
69
|
+
{ checkbox: true }
|
66
70
|
end
|
67
71
|
|
68
72
|
def conditional_classes
|
@@ -9,19 +9,19 @@ module GOVUKDesignSystemFormBuilder
|
|
9
9
|
|
10
10
|
SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
|
11
11
|
|
12
|
-
def initialize(builder, object_name, attribute_name, legend:, caption:,
|
12
|
+
def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, date_of_birth: false, omit_day:, form_group:, &block)
|
13
13
|
super(builder, object_name, attribute_name, &block)
|
14
14
|
|
15
|
-
@legend
|
16
|
-
@caption
|
17
|
-
@
|
18
|
-
@date_of_birth
|
19
|
-
@omit_day
|
20
|
-
@
|
15
|
+
@legend = legend
|
16
|
+
@caption = caption
|
17
|
+
@hint = hint
|
18
|
+
@date_of_birth = date_of_birth
|
19
|
+
@omit_day = omit_day
|
20
|
+
@form_group = form_group
|
21
21
|
end
|
22
22
|
|
23
23
|
def html
|
24
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name,
|
24
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
25
25
|
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
26
26
|
safe_join([supplemental_content, hint_element, error_element, date])
|
27
27
|
end
|
@@ -8,18 +8,18 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
include Traits::Label
|
9
9
|
include Traits::Supplemental
|
10
10
|
|
11
|
-
def initialize(builder, object_name, attribute_name,
|
11
|
+
def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
|
12
12
|
super(builder, object_name, attribute_name, &block)
|
13
13
|
|
14
|
-
@label
|
15
|
-
@caption
|
16
|
-
@
|
17
|
-
@extra_options
|
18
|
-
@
|
14
|
+
@label = label
|
15
|
+
@caption = caption
|
16
|
+
@hint = hint
|
17
|
+
@extra_options = kwargs
|
18
|
+
@form_group = form_group
|
19
19
|
end
|
20
20
|
|
21
21
|
def html
|
22
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name,
|
22
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
23
23
|
safe_join([label_element, supplemental_content, hint_element, error_element, file])
|
24
24
|
end
|
25
25
|
end
|
@@ -3,26 +3,53 @@ module GOVUKDesignSystemFormBuilder
|
|
3
3
|
class Hint < Base
|
4
4
|
using PrefixableArray
|
5
5
|
|
6
|
-
include Traits::Hint
|
7
6
|
include Traits::Localisation
|
8
7
|
|
9
|
-
def initialize(builder, object_name, attribute_name, text,
|
8
|
+
def initialize(builder, object_name, attribute_name, value: nil, text: nil, content: nil, radio: false, checkbox: false, **kwargs)
|
10
9
|
super(builder, object_name, attribute_name)
|
11
10
|
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
|
11
|
+
@radio = radio
|
12
|
+
@checkbox = checkbox
|
13
|
+
@html_attributes = kwargs
|
14
|
+
|
15
|
+
if content
|
16
|
+
@content = capture { content.call }
|
17
|
+
else
|
18
|
+
@text = retrieve_text(text)
|
19
|
+
@value = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def active?
|
24
|
+
[@text, @content].any?(&:present?)
|
16
25
|
end
|
17
26
|
|
18
27
|
def html
|
19
|
-
return nil
|
28
|
+
return nil unless active?
|
29
|
+
|
30
|
+
content_tag(hint_tag, **hint_options, **@html_attributes) { hint_body }
|
31
|
+
end
|
32
|
+
|
33
|
+
def hint_id
|
34
|
+
return nil unless active?
|
20
35
|
|
21
|
-
|
36
|
+
build_id('hint')
|
22
37
|
end
|
23
38
|
|
24
39
|
private
|
25
40
|
|
41
|
+
def hint_options
|
42
|
+
{ class: classes, id: hint_id }
|
43
|
+
end
|
44
|
+
|
45
|
+
def hint_tag
|
46
|
+
@content.presence ? 'div' : 'span'
|
47
|
+
end
|
48
|
+
|
49
|
+
def hint_body
|
50
|
+
@content || @text
|
51
|
+
end
|
52
|
+
|
26
53
|
def retrieve_text(supplied)
|
27
54
|
supplied.presence || localised_text(:hint)
|
28
55
|
end
|
@@ -12,7 +12,7 @@ module GOVUKDesignSystemFormBuilder
|
|
12
12
|
# content is passed in directly via a proc and overrides
|
13
13
|
# the other display options
|
14
14
|
if content
|
15
|
-
@content = content.call
|
15
|
+
@content = capture { content.call }
|
16
16
|
else
|
17
17
|
@value = value # used by field_id
|
18
18
|
@text = retrieve_text(text, hidden)
|
@@ -26,7 +26,7 @@ module GOVUKDesignSystemFormBuilder
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def html
|
29
|
-
return nil
|
29
|
+
return nil unless active?
|
30
30
|
|
31
31
|
if @tag.present?
|
32
32
|
content_tag(@tag, class: %(#{brand}-label-wrapper)) { label }
|
@@ -35,6 +35,10 @@ module GOVUKDesignSystemFormBuilder
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def active?
|
39
|
+
[@content, @text].any?(&:present?)
|
40
|
+
end
|
41
|
+
|
38
42
|
private
|
39
43
|
|
40
44
|
def label
|
@@ -6,25 +6,25 @@ module GOVUKDesignSystemFormBuilder
|
|
6
6
|
include Traits::Hint
|
7
7
|
include Traits::Supplemental
|
8
8
|
|
9
|
-
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:,
|
9
|
+
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint:, legend:, caption:, inline:, small:, bold_labels:, classes:, form_group:, &block)
|
10
10
|
super(builder, object_name, attribute_name, &block)
|
11
11
|
|
12
|
-
@collection
|
13
|
-
@value_method
|
14
|
-
@text_method
|
15
|
-
@hint_method
|
16
|
-
@inline
|
17
|
-
@small
|
18
|
-
@legend
|
19
|
-
@caption
|
20
|
-
@
|
21
|
-
@classes
|
22
|
-
@
|
23
|
-
@bold_labels
|
12
|
+
@collection = collection
|
13
|
+
@value_method = value_method
|
14
|
+
@text_method = text_method
|
15
|
+
@hint_method = hint_method
|
16
|
+
@inline = inline
|
17
|
+
@small = small
|
18
|
+
@legend = legend
|
19
|
+
@caption = caption
|
20
|
+
@hint = hint
|
21
|
+
@classes = classes
|
22
|
+
@form_group = form_group
|
23
|
+
@bold_labels = hint_method.present? || bold_labels
|
24
24
|
end
|
25
25
|
|
26
26
|
def html
|
27
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name,
|
27
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
28
28
|
Containers::Fieldset.new(@builder, @object_name, @attribute_name, **fieldset_options).html do
|
29
29
|
safe_join([supplemental_content, hint_element, error_element, radios])
|
30
30
|
end
|
@@ -41,7 +41,15 @@ module GOVUKDesignSystemFormBuilder
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def hint_element
|
44
|
-
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name,
|
44
|
+
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
|
45
|
+
end
|
46
|
+
|
47
|
+
def hint_content
|
48
|
+
{ text: @hint_text }
|
49
|
+
end
|
50
|
+
|
51
|
+
def hint_options
|
52
|
+
{ value: @value, radio: true }
|
45
53
|
end
|
46
54
|
|
47
55
|
def label_element
|
@@ -8,12 +8,12 @@ module GOVUKDesignSystemFormBuilder
|
|
8
8
|
include Traits::Hint
|
9
9
|
include Traits::Conditional
|
10
10
|
|
11
|
-
def initialize(builder, object_name, attribute_name, value, label:,
|
11
|
+
def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, &block)
|
12
12
|
super(builder, object_name, attribute_name)
|
13
13
|
|
14
14
|
@value = value
|
15
15
|
@label = label
|
16
|
-
@
|
16
|
+
@hint = hint
|
17
17
|
@link_errors = has_errors? && link_errors
|
18
18
|
|
19
19
|
if block_given?
|
@@ -34,16 +34,24 @@ module GOVUKDesignSystemFormBuilder
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def radio_options
|
38
|
+
{ radio: true }
|
39
|
+
end
|
40
|
+
|
37
41
|
def label_element
|
38
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
|
42
|
+
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options, **@label)
|
39
43
|
end
|
40
44
|
|
41
45
|
def label_options
|
42
|
-
{
|
46
|
+
{ value: @value, link_errors: @link_errors }.merge(radio_options)
|
43
47
|
end
|
44
48
|
|
45
49
|
def hint_element
|
46
|
-
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name,
|
50
|
+
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
|
51
|
+
end
|
52
|
+
|
53
|
+
def hint_options
|
54
|
+
{ value: @value }.merge(radio_options)
|
47
55
|
end
|
48
56
|
|
49
57
|
def input
|
@@ -6,22 +6,22 @@ module GOVUKDesignSystemFormBuilder
|
|
6
6
|
include Traits::Hint
|
7
7
|
include Traits::Supplemental
|
8
8
|
|
9
|
-
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, options: {}, html_options: {},
|
9
|
+
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, options: {}, html_options: {}, hint:, label:, caption:, form_group:, &block)
|
10
10
|
super(builder, object_name, attribute_name, &block)
|
11
11
|
|
12
|
-
@collection
|
13
|
-
@value_method
|
14
|
-
@text_method
|
15
|
-
@options
|
16
|
-
@html_options
|
17
|
-
@label
|
18
|
-
@caption
|
19
|
-
@
|
20
|
-
@
|
12
|
+
@collection = collection
|
13
|
+
@value_method = value_method
|
14
|
+
@text_method = text_method
|
15
|
+
@options = options
|
16
|
+
@html_options = html_options
|
17
|
+
@label = label
|
18
|
+
@caption = caption
|
19
|
+
@hint = hint
|
20
|
+
@form_group = form_group
|
21
21
|
end
|
22
22
|
|
23
23
|
def html
|
24
|
-
Containers::FormGroup.new(@builder, @object_name, @attribute_name,
|
24
|
+
Containers::FormGroup.new(@builder, @object_name, @attribute_name, **@form_group).html do
|
25
25
|
safe_join([label_element, supplemental_content, hint_element, error_element, select])
|
26
26
|
end
|
27
27
|
end
|