govuk_design_system_formbuilder 2.0.0b4 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -25
- data/lib/govuk_design_system_formbuilder.rb +2 -2
- data/lib/govuk_design_system_formbuilder/builder.rb +17 -10
- data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +5 -1
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +2 -13
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +10 -5
- data/lib/govuk_design_system_formbuilder/elements/hint.rb +1 -1
- data/lib/govuk_design_system_formbuilder/elements/legend.rb +13 -7
- data/lib/govuk_design_system_formbuilder/elements/null.rb +19 -0
- data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +2 -17
- data/lib/govuk_design_system_formbuilder/traits/caption.rb +5 -5
- data/lib/govuk_design_system_formbuilder/traits/fieldset_item.rb +31 -0
- data/lib/govuk_design_system_formbuilder/traits/hint.rb +5 -3
- data/lib/govuk_design_system_formbuilder/traits/label.rb +5 -1
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bf39d8cfcafbc412e81222f437a8a4b6ccd446fbbf8a389a3ce95fc8ac5b403
|
4
|
+
data.tar.gz: 211f72eccb795874319dcda270d7dd43d79cf446ea4fd4ee1ae20a2bfde35f37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da6cfc65ca96b181110a040339c39073f22652ec3d71dc20124cefe592cfa87d2faba5ddbaa3eed554c511a7775680b82576bd2fcff2152027f1d974b2967bcf
|
7
|
+
data.tar.gz: 80726be73183e18389a990c66f39b7a19089a87f6ccc252c58eaff92b242e012d34ea656d87898199fff64d00cf778b30df9fcea08bb28e2eca4a4798aa65c9f
|
data/README.md
CHANGED
@@ -7,41 +7,32 @@
|
|
7
7
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/fde73b5dc9476197281b/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk_design_system_formbuilder/test_coverage)
|
8
8
|
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=DFE-Digital/govuk_design_system_formbuilder)](https://dependabot.com)
|
9
9
|
[![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk_design_system_formbuilder)](https://github.com/DFE-Digital/govuk_design_system_formbuilder/blob/master/LICENSE)
|
10
|
-
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.9.
|
10
|
+
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.9.1-brightgreen)](https://design-system.service.gov.uk)
|
11
11
|
|
12
|
-
This
|
13
|
-
fully-compliant with version 3.9.0 of the [GOV.UK Design System](https://design-system.service.gov.uk/),
|
14
|
-
minimising the amount of markup you need to write.
|
12
|
+
This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
|
15
13
|
|
16
|
-
|
17
|
-
System is exposed via the API. Adding [JavaScript-enhanced word count
|
18
|
-
checking](https://govuk-form-builder.netlify.app/form-elements/text-area/)
|
19
|
-
to text areas or [setting the size and weight of
|
20
|
-
labels](https://govuk-form-builder.netlify.app/introduction/labels-hints-and-legends/)
|
21
|
-
on text fields requires only a single argument.
|
14
|
+
It is intended to make creating forms **quick**, **easy** and **familiar** for Ruby on Rails developers.
|
22
15
|
|
23
16
|
## Documentation 📚
|
24
17
|
|
25
18
|
The gem comes with [a full guide](https://govuk-form-builder.netlify.app/) that
|
26
|
-
covers most aspects of day-to-day use, along with code and output examples. The
|
27
|
-
|
28
|
-
|
29
|
-
If you're still not sure what a form builder is or how it works, don't worry!
|
30
|
-
[This screencast](https://www.youtube.com/watch?v=PhoFZ0qXAlA) should give you
|
31
|
-
an idea of what's on offer and the official guide goes into a bit more depth on
|
32
|
-
how everything works.
|
19
|
+
covers most aspects of day-to-day use, along with code and output examples. The
|
20
|
+
examples in the guide are generated from the builder itself so it will always
|
21
|
+
be up to date.
|
33
22
|
|
34
23
|
[![Netlify Status](https://api.netlify.com/api/v1/badges/d4c50b8d-6ca3-4797-9ab3-6e0731c72b44/deploy-status)](https://app.netlify.com/sites/govuk-form-builder/deploys)
|
35
24
|
|
36
25
|
## What's included 🧳
|
37
26
|
|
38
27
|
* 100% compatibility with the GOV.UK Design System
|
39
|
-
* Full control of labels, hints,
|
28
|
+
* Full control of labels, legends, hints, captions and fieldsets
|
40
29
|
* No overwriting of Rails' default form helpers
|
41
30
|
* Automatic ARIA associations between hints, errors and inputs
|
42
31
|
* Most helpers take blocks for arbitrary content
|
43
32
|
* Additional params for programmatically adding hints to check box and radio
|
44
33
|
button collections
|
34
|
+
* Full I18n support
|
35
|
+
* Automatic handling of ActiveRecord validation error messages
|
45
36
|
* No external dependencies
|
46
37
|
* An exhaustive test suite
|
47
38
|
* [Extensive technical documentation](https://www.rubydoc.info/gems/govuk_design_system_formbuilder/GOVUKDesignSystemFormBuilder/Builder)
|
@@ -68,8 +59,9 @@ pre-configured template:
|
|
68
59
|
|
69
60
|
## Setup 🔧
|
70
61
|
|
71
|
-
To use the form builder in an ad hoc basis you can specify it
|
72
|
-
|
62
|
+
To use the form builder in an ad hoc basis you can specify it as an argument to
|
63
|
+
`form_for` or `form_with`. These examples are written in [Slim](https://slim-lang.com) but
|
64
|
+
other templating languages like ERB and [Haml](https://haml.info/) work just as well.
|
73
65
|
|
74
66
|
```slim
|
75
67
|
= form_for @some_object, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f|
|
@@ -99,16 +91,16 @@ Now we can get started!
|
|
99
91
|
:name,
|
100
92
|
:description,
|
101
93
|
label: { text: "Which department do you work for?" },
|
102
|
-
|
94
|
+
hint: { text: "If you don't know ask your manager" }
|
103
95
|
|
104
96
|
= f.govuk_submit 'Away we go!'
|
105
97
|
```
|
106
98
|
|
107
99
|
## Developing and running the tests 👨🏻🏭
|
108
100
|
|
109
|
-
The form builder is
|
110
|
-
|
111
|
-
|
101
|
+
The form builder is tested with RSpec. To run all the tests first ensure that
|
102
|
+
the development and testing prerequisite gems are installed. At the root of a
|
103
|
+
freshly-cloned repo run:
|
112
104
|
|
113
105
|
```sh
|
114
106
|
bundle
|
@@ -117,7 +109,7 @@ bundle
|
|
117
109
|
Now, if everything was successful, run RSpec:
|
118
110
|
|
119
111
|
```sh
|
120
|
-
bundle exec rspec
|
112
|
+
bundle exec rspec
|
121
113
|
```
|
122
114
|
|
123
115
|
## Contributing 📦
|
@@ -21,7 +21,7 @@ module GOVUKDesignSystemFormBuilder
|
|
21
21
|
# Can be either +xl+, +l+, +m+ or +s+.
|
22
22
|
#
|
23
23
|
# * +:default_legend_tag+ controls the default tag that legends are
|
24
|
-
# wrapped in. Defaults to +
|
24
|
+
# wrapped in. Defaults to +nil+.
|
25
25
|
#
|
26
26
|
# * +:default_submit_button_text+ sets the value assigned to +govuk_submit+,
|
27
27
|
# defaults to 'Continue'.
|
@@ -47,7 +47,7 @@ module GOVUKDesignSystemFormBuilder
|
|
47
47
|
brand: 'govuk',
|
48
48
|
|
49
49
|
default_legend_size: 'm',
|
50
|
-
default_legend_tag:
|
50
|
+
default_legend_tag: nil,
|
51
51
|
default_caption_size: 'm',
|
52
52
|
default_submit_button_text: 'Continue',
|
53
53
|
default_radio_divider_text: 'or',
|
@@ -459,7 +459,7 @@ module GOVUKDesignSystemFormBuilder
|
|
459
459
|
# @param classes [Array,String] Classes to add to the radio button container.
|
460
460
|
# @option legend text [String] the fieldset legend's text content
|
461
461
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
462
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
462
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
463
463
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
464
464
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
465
465
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
@@ -538,7 +538,7 @@ module GOVUKDesignSystemFormBuilder
|
|
538
538
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
539
539
|
# @option legend text [String] the fieldset legend's text content
|
540
540
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
541
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
541
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
542
542
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
543
543
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
544
544
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
@@ -635,7 +635,7 @@ module GOVUKDesignSystemFormBuilder
|
|
635
635
|
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
636
636
|
# @option legend text [String] the fieldset legend's text content
|
637
637
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
638
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
638
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
639
639
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
640
640
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
641
641
|
# @option caption text [String] the caption text
|
@@ -713,7 +713,7 @@ module GOVUKDesignSystemFormBuilder
|
|
713
713
|
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
714
714
|
# @option legend text [String] the fieldset legend's text content
|
715
715
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
716
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
716
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
717
717
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
718
718
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
719
719
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
@@ -816,6 +816,8 @@ module GOVUKDesignSystemFormBuilder
|
|
816
816
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
817
817
|
# @note Only the first additional button or link (passed in via a block) will be given the
|
818
818
|
# correct left margin, subsequent buttons will need to be manually accounted for
|
819
|
+
# @note This helper always renders an +<input type='submit'>+ tag, HTML content is not supported inside. You
|
820
|
+
# can place +<button>+ tags inside the form to have the same effect
|
819
821
|
# @see https://design-system.service.gov.uk/components/button/#stop-users-from-accidentally-sending-information-more-than-once
|
820
822
|
# GOV.UK double click prevention
|
821
823
|
#
|
@@ -840,7 +842,7 @@ module GOVUKDesignSystemFormBuilder
|
|
840
842
|
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
841
843
|
# @option legend text [String] the fieldset legend's text content
|
842
844
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
843
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
845
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
844
846
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
845
847
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
846
848
|
# @param caption [Hash] configures or sets the caption content which is inserted above the legend
|
@@ -878,13 +880,18 @@ module GOVUKDesignSystemFormBuilder
|
|
878
880
|
# part of the form that contains the error
|
879
881
|
#
|
880
882
|
# @param title [String] the error summary heading
|
883
|
+
# @param link_base_errors_to [Symbol,String] set the field that errors on +:base+ are linked
|
884
|
+
# to, as there won't be a field representing the object base.
|
885
|
+
#
|
886
|
+
# @note Only the first error in the +#errors+ array for each attribute will
|
887
|
+
# be included.
|
881
888
|
#
|
882
889
|
# @example An error summary with a custom title
|
883
890
|
# = f.govuk_error_summary 'Uh-oh, spaghettios'
|
884
891
|
#
|
885
892
|
# @see https://design-system.service.gov.uk/components/error-summary/ GOV.UK error summary
|
886
|
-
def govuk_error_summary(title = config.default_error_summary_title)
|
887
|
-
Elements::ErrorSummary.new(self, object_name, title).html
|
893
|
+
def govuk_error_summary(title = config.default_error_summary_title, link_base_errors_to: nil)
|
894
|
+
Elements::ErrorSummary.new(self, object_name, title, link_base_errors_to: link_base_errors_to).html
|
888
895
|
end
|
889
896
|
|
890
897
|
# Generates a fieldset containing the contents of the block
|
@@ -893,7 +900,7 @@ module GOVUKDesignSystemFormBuilder
|
|
893
900
|
# @param described_by [Array<String>] the ids of the elements that describe this fieldset, usually hints and errors
|
894
901
|
# @option legend text [String] the fieldset legend's text content
|
895
902
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
896
|
-
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1
|
903
|
+
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
897
904
|
# @option legend hidden [Boolean] control the visibility of the legend. Hidden legends will still be read by screenreaders
|
898
905
|
# @option legend kwargs [Hash] additional arguments are applied as attributes on the +legend+ element
|
899
906
|
# @param caption [Hash] configures or sets the caption content which is inserted above the label
|
@@ -902,13 +909,13 @@ module GOVUKDesignSystemFormBuilder
|
|
902
909
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
903
910
|
#
|
904
911
|
# @example A fieldset containing address fields
|
905
|
-
# = f.govuk_fieldset legend: { text: 'Address' }
|
912
|
+
# = f.govuk_fieldset legend: { text: 'Address' } do
|
906
913
|
# = f.govuk_text_field :street
|
907
914
|
# = f.govuk_text_field :town
|
908
915
|
# = f.govuk_text_field :city
|
909
916
|
#
|
910
917
|
# @example A fieldset with the legend as a proc
|
911
|
-
# = f.govuk_fieldset legend: -> { tag.h3('Skills') }
|
918
|
+
# = f.govuk_fieldset legend: -> { tag.h3('Skills') } do
|
912
919
|
# = f.govuk_text_area :physical
|
913
920
|
# = f.govuk_text_area :mental
|
914
921
|
#
|
@@ -30,7 +30,11 @@ module GOVUKDesignSystemFormBuilder
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def legend_element
|
33
|
-
@legend_element ||=
|
33
|
+
@legend_element ||= if @legend.nil?
|
34
|
+
Elements::Null.new
|
35
|
+
else
|
36
|
+
Elements::Legend.new(@builder, @object_name, @attribute_name, **legend_options)
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
36
40
|
def legend_options
|
@@ -6,6 +6,7 @@ module GOVUKDesignSystemFormBuilder
|
|
6
6
|
|
7
7
|
include Traits::Label
|
8
8
|
include Traits::Hint
|
9
|
+
include Traits::FieldsetItem
|
9
10
|
include Traits::Conditional
|
10
11
|
|
11
12
|
def initialize(builder, object_name, attribute_name, value, unchecked_value, label:, hint:, link_errors:, multiple:, &block)
|
@@ -54,19 +55,7 @@ module GOVUKDesignSystemFormBuilder
|
|
54
55
|
%w(checkboxes__input).prefix(brand)
|
55
56
|
end
|
56
57
|
|
57
|
-
def
|
58
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
|
59
|
-
end
|
60
|
-
|
61
|
-
def label_options
|
62
|
-
{ checkbox: true, value: @value, link_errors: @link_errors }
|
63
|
-
end
|
64
|
-
|
65
|
-
def hint_element
|
66
|
-
@hint_element ||= Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
|
67
|
-
end
|
68
|
-
|
69
|
-
def hint_options
|
58
|
+
def fieldset_options
|
70
59
|
{ checkbox: true }
|
71
60
|
end
|
72
61
|
|
@@ -3,10 +3,11 @@ module GOVUKDesignSystemFormBuilder
|
|
3
3
|
class ErrorSummary < Base
|
4
4
|
include Traits::Error
|
5
5
|
|
6
|
-
def initialize(builder, object_name, title)
|
7
|
-
@builder
|
8
|
-
@object_name
|
9
|
-
@title
|
6
|
+
def initialize(builder, object_name, title, link_base_errors_to:)
|
7
|
+
@builder = builder
|
8
|
+
@object_name = object_name
|
9
|
+
@title = title
|
10
|
+
@link_base_errors_to = link_base_errors_to
|
10
11
|
end
|
11
12
|
|
12
13
|
def html
|
@@ -54,7 +55,11 @@ module GOVUKDesignSystemFormBuilder
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def field_id(attribute)
|
57
|
-
|
58
|
+
if attribute.eql?(:base) && @link_base_errors_to.present?
|
59
|
+
build_id('field', attribute_name: @link_base_errors_to)
|
60
|
+
else
|
61
|
+
build_id('field-error', attribute_name: attribute)
|
62
|
+
end
|
58
63
|
end
|
59
64
|
|
60
65
|
def summary_title_id
|
@@ -11,7 +11,7 @@ module GOVUKDesignSystemFormBuilder
|
|
11
11
|
|
12
12
|
case legend
|
13
13
|
when NilClass
|
14
|
-
|
14
|
+
# do nothing
|
15
15
|
when Proc
|
16
16
|
@raw = capture { legend.call }
|
17
17
|
when Hash
|
@@ -23,7 +23,7 @@ module GOVUKDesignSystemFormBuilder
|
|
23
23
|
@caption = caption
|
24
24
|
end
|
25
25
|
else
|
26
|
-
fail(ArgumentError, %(legend must be a Proc or Hash))
|
26
|
+
fail(ArgumentError, %(legend must be a NilClass, Proc or Hash))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -38,12 +38,18 @@ module GOVUKDesignSystemFormBuilder
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def content
|
41
|
-
return
|
41
|
+
return unless active?
|
42
42
|
|
43
|
-
tag.legend(class: classes, **@html_attributes)
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
tag.legend(legend_text, class: classes, **@html_attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
def legend_text
|
47
|
+
caption_and_text = safe_join([caption_element, @text])
|
48
|
+
|
49
|
+
if @tag.present?
|
50
|
+
content_tag(@tag, class: heading_classes) { caption_and_text }
|
51
|
+
else
|
52
|
+
caption_and_text
|
47
53
|
end
|
48
54
|
end
|
49
55
|
|
@@ -6,6 +6,7 @@ module GOVUKDesignSystemFormBuilder
|
|
6
6
|
|
7
7
|
include Traits::Label
|
8
8
|
include Traits::Hint
|
9
|
+
include Traits::FieldsetItem
|
9
10
|
include Traits::Conditional
|
10
11
|
|
11
12
|
def initialize(builder, object_name, attribute_name, value, label:, hint:, link_errors:, &block)
|
@@ -34,26 +35,10 @@ module GOVUKDesignSystemFormBuilder
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
def
|
38
|
+
def fieldset_options
|
38
39
|
{ radio: true }
|
39
40
|
end
|
40
41
|
|
41
|
-
def label_element
|
42
|
-
@label_element ||= Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
|
43
|
-
end
|
44
|
-
|
45
|
-
def label_options
|
46
|
-
{ value: @value, link_errors: @link_errors }.merge(radio_options)
|
47
|
-
end
|
48
|
-
|
49
|
-
def hint_element
|
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)
|
55
|
-
end
|
56
|
-
|
57
42
|
def input
|
58
43
|
@builder.radio_button(@attribute_name, @value, **options)
|
59
44
|
end
|
@@ -4,11 +4,11 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
private
|
5
5
|
|
6
6
|
def caption_element
|
7
|
-
@caption_element ||=
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
@caption_element ||= if @caption.nil?
|
8
|
+
Elements::Null.new
|
9
|
+
else
|
10
|
+
Elements::Caption.new(@builder, @object_name, @attribute_name, **@caption)
|
11
|
+
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GOVUKDesignSystemFormBuilder
|
2
|
+
module Traits
|
3
|
+
module FieldsetItem
|
4
|
+
private
|
5
|
+
|
6
|
+
def label_element
|
7
|
+
@label_element ||= if @label.nil?
|
8
|
+
Elements::Null.new
|
9
|
+
else
|
10
|
+
Elements::Label.new(@builder, @object_name, @attribute_name, **label_content, **label_options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def label_options
|
15
|
+
{ value: @value, link_errors: @link_errors }.merge(fieldset_options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def hint_element
|
19
|
+
@hint_element ||= if @hint.nil?
|
20
|
+
Elements::Null.new
|
21
|
+
else
|
22
|
+
Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_options, **hint_content)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def hint_options
|
27
|
+
{ value: @value }.merge(fieldset_options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -10,13 +10,15 @@ module GOVUKDesignSystemFormBuilder
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def hint_element
|
13
|
-
@hint_element ||=
|
13
|
+
@hint_element ||= if @hint.nil?
|
14
|
+
Elements::Null.new
|
15
|
+
else
|
16
|
+
Elements::Hint.new(@builder, @object_name, @attribute_name, **hint_content)
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
def hint_content
|
17
21
|
case @hint
|
18
|
-
when NilClass
|
19
|
-
{}
|
20
22
|
when Hash
|
21
23
|
@hint
|
22
24
|
when Proc
|
@@ -4,7 +4,11 @@ module GOVUKDesignSystemFormBuilder
|
|
4
4
|
private
|
5
5
|
|
6
6
|
def label_element
|
7
|
-
@label_element ||=
|
7
|
+
@label_element ||= if @label.nil?
|
8
|
+
Elements::Null.new
|
9
|
+
else
|
10
|
+
Elements::Label.new(@builder, @object_name, @attribute_name, caption: @caption, **label_content)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def label_content
|
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: 2.
|
4
|
+
version: 2.1.3
|
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-11-03 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.17.
|
61
|
+
version: 3.17.2
|
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.17.
|
68
|
+
version: 3.17.2
|
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.24.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.24.0
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: rubypants
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -278,6 +278,7 @@ files:
|
|
278
278
|
- lib/govuk_design_system_formbuilder/elements/inputs/url.rb
|
279
279
|
- lib/govuk_design_system_formbuilder/elements/label.rb
|
280
280
|
- lib/govuk_design_system_formbuilder/elements/legend.rb
|
281
|
+
- lib/govuk_design_system_formbuilder/elements/null.rb
|
281
282
|
- lib/govuk_design_system_formbuilder/elements/radios/collection.rb
|
282
283
|
- lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb
|
283
284
|
- lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb
|
@@ -288,6 +289,7 @@ files:
|
|
288
289
|
- lib/govuk_design_system_formbuilder/traits/collection_item.rb
|
289
290
|
- lib/govuk_design_system_formbuilder/traits/conditional.rb
|
290
291
|
- lib/govuk_design_system_formbuilder/traits/error.rb
|
292
|
+
- lib/govuk_design_system_formbuilder/traits/fieldset_item.rb
|
291
293
|
- lib/govuk_design_system_formbuilder/traits/hint.rb
|
292
294
|
- lib/govuk_design_system_formbuilder/traits/input.rb
|
293
295
|
- lib/govuk_design_system_formbuilder/traits/label.rb
|
@@ -314,9 +316,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
314
316
|
version: '0'
|
315
317
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
316
318
|
requirements:
|
317
|
-
- - "
|
319
|
+
- - ">="
|
318
320
|
- !ruby/object:Gem::Version
|
319
|
-
version:
|
321
|
+
version: '0'
|
320
322
|
requirements: []
|
321
323
|
rubygems_version: 3.1.2
|
322
324
|
signing_key:
|