govuk_design_system_formbuilder 3.2.0 → 4.0.0a1
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/README.md +2 -2
- data/lib/govuk_design_system_formbuilder/builder.rb +11 -30
- data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +11 -13
- data/lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb +9 -9
- data/lib/govuk_design_system_formbuilder/containers/form_group.rb +12 -17
- data/lib/govuk_design_system_formbuilder/containers/radio_buttons_fieldset.rb +9 -9
- data/lib/govuk_design_system_formbuilder/containers/radios.rb +12 -18
- data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection.rb +13 -13
- data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +4 -10
- data/lib/govuk_design_system_formbuilder/elements/radios/collection.rb +15 -15
- data/lib/govuk_design_system_formbuilder/elements/submit.rb +10 -25
- data/lib/govuk_design_system_formbuilder/traits/localisation.rb +12 -2
- data/lib/govuk_design_system_formbuilder/version.rb +1 -1
- data/lib/govuk_design_system_formbuilder.rb +8 -0
- metadata +12 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb63962a20ab569ce6283535831fd253e20d993436d554d47807472ce51e22cd
|
|
4
|
+
data.tar.gz: fc6356cac0b5bcf49292ae825a0ef5a467b4f44cc137570a9b0e7db8ae857c2d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ab50e0155a076d8bd2f4720286ff5415b993f56f741d6fa4abb0c1085442618e0afe12aa9f9035e1599c0cb55af8b15864315a1596971ae055c13ff4a7b56ee2
|
|
7
|
+
data.tar.gz: 06d4e19e2d00f9556088a8a9a77dd1b23158b7091021fd183dcb9874dc66c018f66c6e97b6c018f97bb4a64aea528d5f50d57e36953f9079a6adc3a3e54ed14b
|
data/README.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
[](https://rubygems.org/gems/govuk_design_system_formbuilder)
|
|
7
7
|
[](https://codeclimate.com/github/DFE-Digital/govuk-formbuilder/test_coverage)
|
|
8
8
|
[](https://github.com/DFE-Digital/govuk-formbuilder/blob/main/LICENSE)
|
|
9
|
-
[](https://design-system.service.gov.uk)
|
|
10
10
|
[](https://weblog.rubyonrails.org/releases/)
|
|
11
|
-
[](https://www.ruby-lang.org/en/downloads/)
|
|
12
12
|
|
|
13
13
|
This library provides an easy-to-use form builder for the [GOV.UK Design System](https://design-system.service.gov.uk/).
|
|
14
14
|
|
|
@@ -24,7 +24,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
24
24
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
25
25
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
26
26
|
# @param form_group [Hash] configures the form group
|
|
27
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
28
27
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
29
28
|
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
30
29
|
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
@@ -76,7 +75,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
76
75
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
77
76
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
78
77
|
# @param form_group [Hash] configures the form group
|
|
79
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
80
78
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
81
79
|
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
82
80
|
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
@@ -129,7 +127,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
129
127
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
130
128
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
131
129
|
# @param form_group [Hash] configures the form group
|
|
132
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
133
130
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
134
131
|
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
135
132
|
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
@@ -180,7 +177,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
180
177
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
181
178
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
182
179
|
# @param form_group [Hash] configures the form group
|
|
183
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
184
180
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
185
181
|
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
186
182
|
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
@@ -230,7 +226,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
230
226
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
231
227
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
232
228
|
# @param form_group [Hash] configures the form group
|
|
233
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
234
229
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
235
230
|
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
236
231
|
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
@@ -281,7 +276,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
281
276
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
282
277
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
283
278
|
# @param form_group [Hash] configures the form group
|
|
284
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
285
279
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
286
280
|
# @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
|
|
287
281
|
# @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
|
|
@@ -339,7 +333,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
339
333
|
# @param rows [Integer] sets the initial number of rows
|
|
340
334
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +textarea+ element
|
|
341
335
|
# @param form_group [Hash] configures the form group
|
|
342
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
343
336
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
344
337
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +textarea+ element
|
|
345
338
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
@@ -389,7 +382,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
389
382
|
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
390
383
|
# @param options [Hash] Options hash passed through to Rails' +collection_select+ helper
|
|
391
384
|
# @param form_group [Hash] configures the form group
|
|
392
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
393
385
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
394
386
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
395
387
|
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select Rails collection_select (called by govuk_collection_select)
|
|
@@ -447,7 +439,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
447
439
|
# @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
|
|
448
440
|
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
|
449
441
|
# @param form_group [Hash] configures the form group
|
|
450
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
451
442
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
452
443
|
# @param block [Block] build the contents of the select element manually for exact control
|
|
453
444
|
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select Rails select (called by govuk_collection_select)
|
|
@@ -494,7 +485,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
494
485
|
# @param small [Boolean] controls whether small radio buttons are used instead of regular-sized ones
|
|
495
486
|
# @param bold_labels [Boolean] controls whether the radio button labels are bold
|
|
496
487
|
# @param include_hidden [Boolean] controls whether a hidden field is inserted to allow for empty submissions
|
|
497
|
-
# @param classes [Array,String] Classes to add to the radio button container.
|
|
498
488
|
# @option legend text [String] the fieldset legend's text content
|
|
499
489
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
500
490
|
# @option legend tag [Symbol,String] the tag used for the fieldset's header, defaults to +h1+.
|
|
@@ -538,7 +528,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
538
528
|
# :name,
|
|
539
529
|
# legend: -> { tag.h3('Which category do you belong to?') }
|
|
540
530
|
#
|
|
541
|
-
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: nil,
|
|
531
|
+
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil, hint: {}, legend: {}, caption: {}, inline: false, small: false, bold_labels: nil, include_hidden: config.default_collection_radio_buttons_include_hidden, form_group: {}, **kwargs, &block)
|
|
542
532
|
Elements::Radios::Collection.new(
|
|
543
533
|
self,
|
|
544
534
|
object_name,
|
|
@@ -553,9 +543,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
553
543
|
inline: inline,
|
|
554
544
|
small: small,
|
|
555
545
|
bold_labels: bold_labels,
|
|
556
|
-
classes: classes,
|
|
557
546
|
form_group: form_group,
|
|
558
547
|
include_hidden: include_hidden,
|
|
548
|
+
**kwargs,
|
|
559
549
|
&block
|
|
560
550
|
).html
|
|
561
551
|
end
|
|
@@ -585,10 +575,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
585
575
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
586
576
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
587
577
|
# @param form_group [Hash] configures the form group
|
|
588
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
589
578
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
590
579
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
|
591
|
-
# @param classes [Array,String] Classes to add to the radio button container.
|
|
592
580
|
# @see https://design-system.service.gov.uk/components/radios/ GOV.UK Radios
|
|
593
581
|
# @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
|
|
594
582
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
@@ -610,8 +598,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
610
598
|
# = f.govuk_radio_button :burger_id, :regular, label: { text: 'Hamburger' }, link_errors: true
|
|
611
599
|
# = f.govuk_radio_button :burger_id, :cheese, label: { text: 'Cheeseburger' }
|
|
612
600
|
#
|
|
613
|
-
def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false,
|
|
614
|
-
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, inline: inline, small: small,
|
|
601
|
+
def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: false, form_group: {}, **kwargs, &block)
|
|
602
|
+
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name, hint: hint, legend: legend, caption: caption, inline: inline, small: small, form_group: form_group, **kwargs, &block).html
|
|
615
603
|
end
|
|
616
604
|
|
|
617
605
|
# Generates a radio button
|
|
@@ -671,7 +659,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
671
659
|
# @option hint text [String] the hint text
|
|
672
660
|
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
673
661
|
# @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
|
|
674
|
-
# @param classes [Array,String] Classes to add to the checkbox container.
|
|
675
662
|
# @param legend [NilClass,Hash,Proc] options for configuring the legend. Legend will be omitted if +nil+.
|
|
676
663
|
# @option legend text [String] the fieldset legend's text content
|
|
677
664
|
# @option legend size [String] the size of the fieldset legend font, can be +xl+, +l+, +m+ or +s+
|
|
@@ -682,7 +669,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
682
669
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
683
670
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
684
671
|
# @param form_group [Hash] configures the form group
|
|
685
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
686
672
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
687
673
|
# @param include_hidden [Boolean] controls whether a hidden field is inserted to allow for empty submissions
|
|
688
674
|
# @param block [Block] any HTML passed in will be injected into the fieldset, after the hint and before the checkboxes
|
|
@@ -703,7 +689,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
703
689
|
# legend: { text: 'What do you want in your sandwich?', size: 'm' },
|
|
704
690
|
# hint: { text: "If it isn't listed here, tough luck" },
|
|
705
691
|
# inline: false,
|
|
706
|
-
#
|
|
692
|
+
# class: 'app-overflow-scroll',
|
|
707
693
|
#
|
|
708
694
|
# @example A collection of check boxes for types of bread
|
|
709
695
|
# = f.govuk_collection_check_boxes :bread,
|
|
@@ -721,7 +707,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
721
707
|
# :name,
|
|
722
708
|
# legend: -> { tag.h3('What kind of sandwich do you want?') }
|
|
723
709
|
#
|
|
724
|
-
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false,
|
|
710
|
+
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil, hint: {}, legend: {}, caption: {}, small: false, form_group: {}, include_hidden: config.default_collection_check_boxes_include_hidden, **kwargs, &block)
|
|
725
711
|
Elements::CheckBoxes::Collection.new(
|
|
726
712
|
self,
|
|
727
713
|
object_name,
|
|
@@ -734,9 +720,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
734
720
|
legend: legend,
|
|
735
721
|
caption: caption,
|
|
736
722
|
small: small,
|
|
737
|
-
classes: classes,
|
|
738
723
|
form_group: form_group,
|
|
739
724
|
include_hidden: include_hidden,
|
|
725
|
+
**kwargs,
|
|
740
726
|
&block
|
|
741
727
|
).html
|
|
742
728
|
end
|
|
@@ -762,11 +748,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
762
748
|
# @option caption text [String] the caption text
|
|
763
749
|
# @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
|
|
764
750
|
# @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
|
|
765
|
-
# @param classes [Array,String] Classes to add to the checkbox container.
|
|
766
751
|
# @param form_group [Hash] configures the form group
|
|
767
752
|
# @param multiple [Boolean] when true adds a +[]+ suffix the +name+ of the automatically-generated hidden field
|
|
768
753
|
# (ie. <code>project[invoice_attributes][]</code>). When false, no +[]+ suffix is added (ie. <code>project[accepted]</code>)
|
|
769
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
770
754
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
771
755
|
# @param block [Block] a block of HTML that will be used to populate the fieldset
|
|
772
756
|
# @return [ActiveSupport::SafeBuffer] HTML output
|
|
@@ -781,7 +765,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
781
765
|
# = f.govuk_check_box :desired_filling, :lemonade, label: { text: 'Lemonade' }, link_errors: true
|
|
782
766
|
# = f.govuk_check_box :desired_filling, :fizzy_orange, label: { text: 'Fizzy orange' }
|
|
783
767
|
#
|
|
784
|
-
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false,
|
|
768
|
+
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: false, form_group: {}, multiple: true, **kwargs, &block)
|
|
785
769
|
Containers::CheckBoxesFieldset.new(
|
|
786
770
|
self,
|
|
787
771
|
object_name,
|
|
@@ -790,9 +774,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
790
774
|
legend: legend,
|
|
791
775
|
caption: caption,
|
|
792
776
|
small: small,
|
|
793
|
-
classes: classes,
|
|
794
777
|
form_group: form_group,
|
|
795
778
|
multiple: multiple,
|
|
779
|
+
**kwargs,
|
|
796
780
|
&block
|
|
797
781
|
).html
|
|
798
782
|
end
|
|
@@ -861,7 +845,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
861
845
|
# @param text [String,Proc] the button text. When a +Proc+ is provided its contents will be rendered within the button element
|
|
862
846
|
# @param warning [Boolean] makes the button red ({https://design-system.service.gov.uk/components/button/#warning-buttons warning}) when true
|
|
863
847
|
# @param secondary [Boolean] makes the button grey ({https://design-system.service.gov.uk/components/button/#secondary-buttons secondary}) when true
|
|
864
|
-
# @param classes [Array,String] Classes to add to the submit button
|
|
865
848
|
# @param prevent_double_click [Boolean] adds JavaScript to safeguard the
|
|
866
849
|
# form from being submitted more than once
|
|
867
850
|
# @param validate [Boolean] adds the formnovalidate to the submit button when true, this disables all
|
|
@@ -886,8 +869,8 @@ module GOVUKDesignSystemFormBuilder
|
|
|
886
869
|
# = f.govuk_submit "Proceed", prevent_double_click: true do
|
|
887
870
|
# = link_to 'Cancel', some_other_path, class: 'govuk-button__secondary'
|
|
888
871
|
#
|
|
889
|
-
def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false,
|
|
890
|
-
Elements::Submit.new(self, text, warning: warning, secondary: secondary,
|
|
872
|
+
def govuk_submit(text = config.default_submit_button_text, warning: false, secondary: false, prevent_double_click: true, validate: config.default_submit_validate, disabled: false, **kwargs, &block)
|
|
873
|
+
Elements::Submit.new(self, text, warning: warning, secondary: secondary, prevent_double_click: prevent_double_click, validate: validate, disabled: disabled, **kwargs, &block).html
|
|
891
874
|
end
|
|
892
875
|
|
|
893
876
|
# Generates three inputs for the +day+, +month+ and +year+ components of a date
|
|
@@ -914,7 +897,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
914
897
|
# @param omit_day [Boolean] do not render a day input, only capture month and year
|
|
915
898
|
# @param maxlength_enabled [Boolean] adds maxlength attribute to day, month and year inputs (2, 2, and 4, respectively)
|
|
916
899
|
# @param form_group [Hash] configures the form group
|
|
917
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
918
900
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
919
901
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
920
902
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input group
|
|
@@ -1021,7 +1003,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
1021
1003
|
# @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
|
|
1022
1004
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
|
1023
1005
|
# @param form_group [Hash] configures the form group
|
|
1024
|
-
# @option form_group classes [Array,String] sets the form group's classes
|
|
1025
1006
|
# @option form_group kwargs [Hash] additional attributes added to the form group
|
|
1026
1007
|
# @param block [Block] arbitrary HTML that will be rendered between the hint and the input
|
|
1027
1008
|
#
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Containers
|
|
3
3
|
class CheckBoxes < Base
|
|
4
|
-
|
|
4
|
+
include Traits::HTMLClasses
|
|
5
|
+
include Traits::HTMLAttributes
|
|
6
|
+
|
|
7
|
+
def initialize(builder, small:, **kwargs)
|
|
5
8
|
super(builder, nil, nil)
|
|
6
9
|
|
|
7
|
-
@small
|
|
8
|
-
@
|
|
10
|
+
@small = small
|
|
11
|
+
@html_attributes = kwargs
|
|
9
12
|
end
|
|
10
13
|
|
|
11
14
|
def html(&block)
|
|
12
|
-
tag.div(**
|
|
15
|
+
tag.div(**attributes(@html_attributes), &block)
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
private
|
|
@@ -22,15 +25,10 @@ module GOVUKDesignSystemFormBuilder
|
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
def classes
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
%(#{brand}-checkboxes--small) if @small
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def custom_classes
|
|
33
|
-
Array.wrap(@classes)
|
|
28
|
+
build_classes(
|
|
29
|
+
%(#{brand}-checkboxes),
|
|
30
|
+
%(#{brand}-checkboxes--small) => @small,
|
|
31
|
+
)
|
|
34
32
|
end
|
|
35
33
|
end
|
|
36
34
|
end
|
|
@@ -4,18 +4,18 @@ module GOVUKDesignSystemFormBuilder
|
|
|
4
4
|
include Traits::Error
|
|
5
5
|
include Traits::Hint
|
|
6
6
|
|
|
7
|
-
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, small:,
|
|
7
|
+
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, small:, form_group:, multiple:, **kwargs, &block)
|
|
8
8
|
fail LocalJumpError, 'no block given' unless block_given?
|
|
9
9
|
|
|
10
10
|
super(builder, object_name, attribute_name, &block)
|
|
11
11
|
|
|
12
|
-
@legend
|
|
13
|
-
@caption
|
|
14
|
-
@hint
|
|
15
|
-
@small
|
|
16
|
-
@
|
|
17
|
-
@
|
|
18
|
-
@
|
|
12
|
+
@legend = legend
|
|
13
|
+
@caption = caption
|
|
14
|
+
@hint = hint
|
|
15
|
+
@small = small
|
|
16
|
+
@form_group = form_group
|
|
17
|
+
@multiple = multiple
|
|
18
|
+
@html_attributes = kwargs
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def html
|
|
@@ -47,7 +47,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def checkboxes
|
|
50
|
-
Containers::CheckBoxes.new(@builder, small: @small,
|
|
50
|
+
Containers::CheckBoxes.new(@builder, small: @small, **@html_attributes).html do
|
|
51
51
|
@block_content
|
|
52
52
|
end
|
|
53
53
|
end
|
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Containers
|
|
3
3
|
class FormGroup < Base
|
|
4
|
-
|
|
4
|
+
include Traits::HTMLAttributes
|
|
5
|
+
include Traits::HTMLClasses
|
|
6
|
+
|
|
7
|
+
def initialize(builder, object_name, attribute_name, **kwargs)
|
|
5
8
|
super(builder, object_name, attribute_name)
|
|
6
9
|
|
|
7
|
-
@classes = classes
|
|
8
10
|
@html_attributes = kwargs
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def html(&block)
|
|
12
|
-
tag.div(
|
|
14
|
+
tag.div(**attributes(@html_attributes), &block)
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
private
|
|
16
18
|
|
|
17
|
-
def
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def error_class
|
|
26
|
-
%(#{brand}-form-group--error) if has_errors?
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def custom_classes
|
|
30
|
-
Array.wrap(@classes)
|
|
19
|
+
def options
|
|
20
|
+
{
|
|
21
|
+
class: build_classes(
|
|
22
|
+
%(#{brand}-form-group),
|
|
23
|
+
%(#{brand}-form-group--error) => has_errors?
|
|
24
|
+
)
|
|
25
|
+
}
|
|
31
26
|
end
|
|
32
27
|
end
|
|
33
28
|
end
|
|
@@ -4,18 +4,18 @@ module GOVUKDesignSystemFormBuilder
|
|
|
4
4
|
include Traits::Hint
|
|
5
5
|
include Traits::Error
|
|
6
6
|
|
|
7
|
-
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, inline:, small:,
|
|
7
|
+
def initialize(builder, object_name, attribute_name, hint:, legend:, caption:, inline:, small:, form_group:, **kwargs, &block)
|
|
8
8
|
fail LocalJumpError, 'no block given' unless block_given?
|
|
9
9
|
|
|
10
10
|
super(builder, object_name, attribute_name, &block)
|
|
11
11
|
|
|
12
|
-
@inline
|
|
13
|
-
@small
|
|
14
|
-
@legend
|
|
15
|
-
@caption
|
|
16
|
-
@hint
|
|
17
|
-
@
|
|
18
|
-
@
|
|
12
|
+
@inline = inline
|
|
13
|
+
@small = small
|
|
14
|
+
@legend = legend
|
|
15
|
+
@caption = caption
|
|
16
|
+
@hint = hint
|
|
17
|
+
@form_group = form_group
|
|
18
|
+
@html_attributes = kwargs
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def html
|
|
@@ -37,7 +37,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def radios
|
|
40
|
-
Containers::Radios.new(@builder, inline: @inline, small: @small,
|
|
40
|
+
Containers::Radios.new(@builder, inline: @inline, small: @small, **@html_attributes).html do
|
|
41
41
|
@block_content
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -2,17 +2,19 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Containers
|
|
3
3
|
class Radios < Base
|
|
4
4
|
include Traits::Hint
|
|
5
|
+
include Traits::HTMLAttributes
|
|
6
|
+
include Traits::HTMLClasses
|
|
5
7
|
|
|
6
|
-
def initialize(builder, inline:, small:,
|
|
8
|
+
def initialize(builder, inline:, small:, **kwargs)
|
|
7
9
|
super(builder, nil, nil)
|
|
8
10
|
|
|
9
|
-
@inline
|
|
10
|
-
@small
|
|
11
|
-
@
|
|
11
|
+
@inline = inline
|
|
12
|
+
@small = small
|
|
13
|
+
@html_attributes = kwargs
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def html(&block)
|
|
15
|
-
tag.div(**
|
|
17
|
+
tag.div(**attributes(@html_attributes), &block)
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
private
|
|
@@ -25,19 +27,11 @@ module GOVUKDesignSystemFormBuilder
|
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
def classes
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def small_class
|
|
36
|
-
%(#{brand}-radios--small) if @small
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def custom_classes
|
|
40
|
-
Array.wrap(@classes)
|
|
30
|
+
build_classes(
|
|
31
|
+
%(#{brand}-radios),
|
|
32
|
+
%(#{brand}-radios--inline) => @inline,
|
|
33
|
+
%(#{brand}-radios--small) => @small,
|
|
34
|
+
)
|
|
41
35
|
end
|
|
42
36
|
end
|
|
43
37
|
end
|
|
@@ -6,20 +6,20 @@ 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:, legend:, caption:, small:,
|
|
9
|
+
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint:, legend:, caption:, small:, form_group:, include_hidden:, hint_method: nil, **kwargs, &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
|
-
@hint
|
|
20
|
-
@
|
|
21
|
-
@
|
|
22
|
-
@
|
|
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
|
+
@form_group = form_group
|
|
21
|
+
@include_hidden = include_hidden
|
|
22
|
+
@html_attributes = kwargs
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def html
|
|
@@ -41,7 +41,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def check_boxes
|
|
44
|
-
Containers::CheckBoxes.new(@builder, small: @small,
|
|
44
|
+
Containers::CheckBoxes.new(@builder, small: @small, **@html_attributes).html do
|
|
45
45
|
collection
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -18,14 +18,16 @@ module GOVUKDesignSystemFormBuilder
|
|
|
18
18
|
return unless object_has_errors?
|
|
19
19
|
|
|
20
20
|
tag.div(**attributes(@html_attributes)) do
|
|
21
|
-
|
|
21
|
+
tag.div(role: "alert") do
|
|
22
|
+
safe_join([title, summary])
|
|
23
|
+
end
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
private
|
|
26
28
|
|
|
27
29
|
def title
|
|
28
|
-
tag.h2(@title,
|
|
30
|
+
tag.h2(@title, class: summary_class('title'))
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
def summary
|
|
@@ -110,10 +112,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
110
112
|
end
|
|
111
113
|
end
|
|
112
114
|
|
|
113
|
-
def summary_title_id
|
|
114
|
-
'error-summary-title'
|
|
115
|
-
end
|
|
116
|
-
|
|
117
115
|
def object_has_errors?
|
|
118
116
|
@builder.object.errors.any?
|
|
119
117
|
end
|
|
@@ -121,13 +119,9 @@ module GOVUKDesignSystemFormBuilder
|
|
|
121
119
|
def options
|
|
122
120
|
{
|
|
123
121
|
class: classes,
|
|
124
|
-
role: 'alert',
|
|
125
122
|
data: {
|
|
126
123
|
module: %(#{brand}-error-summary)
|
|
127
124
|
},
|
|
128
|
-
aria: {
|
|
129
|
-
labelledby: [summary_title_id.presence]
|
|
130
|
-
}
|
|
131
125
|
}
|
|
132
126
|
end
|
|
133
127
|
|
|
@@ -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:, hint_method:, hint:, legend:, caption:, inline:, small:, bold_labels:,
|
|
9
|
+
def initialize(builder, object_name, attribute_name, collection, value_method:, text_method:, hint_method:, hint:, legend:, caption:, inline:, small:, bold_labels:, form_group:, include_hidden:, **kwargs, &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
|
-
@hint
|
|
21
|
-
@
|
|
22
|
-
@
|
|
23
|
-
@
|
|
24
|
-
@
|
|
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
|
+
@form_group = form_group
|
|
22
|
+
@include_hidden = include_hidden
|
|
23
|
+
@bold_labels = (bold_labels.nil? && auto_bold_labels?) || bold_labels
|
|
24
|
+
@html_attributes = kwargs
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def html
|
|
@@ -48,7 +48,7 @@ module GOVUKDesignSystemFormBuilder
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def radios
|
|
51
|
-
Containers::Radios.new(@builder, inline: @inline, small: @small,
|
|
51
|
+
Containers::Radios.new(@builder, inline: @inline, small: @small, **@html_attributes).html do
|
|
52
52
|
safe_join(collection)
|
|
53
53
|
end
|
|
54
54
|
end
|
|
@@ -2,9 +2,10 @@ module GOVUKDesignSystemFormBuilder
|
|
|
2
2
|
module Elements
|
|
3
3
|
class Submit < Base
|
|
4
4
|
using PrefixableArray
|
|
5
|
+
include Traits::HTMLClasses
|
|
5
6
|
include Traits::HTMLAttributes
|
|
6
7
|
|
|
7
|
-
def initialize(builder, text, warning:, secondary:,
|
|
8
|
+
def initialize(builder, text, warning:, secondary:, prevent_double_click:, validate:, disabled:, **kwargs, &block)
|
|
8
9
|
super(builder, nil, nil)
|
|
9
10
|
|
|
10
11
|
fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary
|
|
@@ -13,7 +14,6 @@ module GOVUKDesignSystemFormBuilder
|
|
|
13
14
|
@prevent_double_click = prevent_double_click
|
|
14
15
|
@warning = warning
|
|
15
16
|
@secondary = secondary
|
|
16
|
-
@classes = classes
|
|
17
17
|
@validate = validate
|
|
18
18
|
@disabled = disabled
|
|
19
19
|
@html_attributes = kwargs
|
|
@@ -56,34 +56,19 @@ module GOVUKDesignSystemFormBuilder
|
|
|
56
56
|
disabled: @disabled,
|
|
57
57
|
class: classes,
|
|
58
58
|
data: {
|
|
59
|
-
module
|
|
60
|
-
'prevent-double-click'
|
|
59
|
+
'module' => %(#{brand}-button),
|
|
60
|
+
'prevent-double-click' => @prevent_double_click
|
|
61
61
|
}.select { |_k, v| v.present? }
|
|
62
62
|
}
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def classes
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def warning_class
|
|
74
|
-
%(#{brand}-button--warning) if @warning
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def secondary_class
|
|
78
|
-
%(#{brand}-button--secondary) if @secondary
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def disabled_class
|
|
82
|
-
%(#{brand}-button--disabled) if @disabled
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def custom_classes
|
|
86
|
-
Array.wrap(@classes)
|
|
66
|
+
build_classes(
|
|
67
|
+
"button",
|
|
68
|
+
"button--warning" => @warning,
|
|
69
|
+
"button--secondary" => @secondary,
|
|
70
|
+
"button--disabled" => @disabled,
|
|
71
|
+
).prefix(brand)
|
|
87
72
|
end
|
|
88
73
|
end
|
|
89
74
|
end
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
module GOVUKDesignSystemFormBuilder
|
|
2
2
|
module Traits
|
|
3
3
|
module Localisation
|
|
4
|
+
# starts with an letter that is followed by other word characters or
|
|
5
|
+
# spaces, zero or more times
|
|
6
|
+
BASE_NAME_REGEXP = %r{[[:alpha:]](?:[\w\s]*)}.freeze
|
|
7
|
+
|
|
4
8
|
private
|
|
5
9
|
|
|
6
10
|
def localised_text(context)
|
|
@@ -25,10 +29,16 @@ module GOVUKDesignSystemFormBuilder
|
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
def schema_path
|
|
32
|
+
base_object_name = if config.enable_nested_localisation
|
|
33
|
+
@object_name.to_s.scan(BASE_NAME_REGEXP).join(".")
|
|
34
|
+
else
|
|
35
|
+
@object_name
|
|
36
|
+
end
|
|
37
|
+
|
|
28
38
|
if @value.present?
|
|
29
|
-
[
|
|
39
|
+
[base_object_name, "#{@attribute_name}_options", @value]
|
|
30
40
|
else
|
|
31
|
-
[
|
|
41
|
+
[base_object_name, @attribute_name]
|
|
32
42
|
end
|
|
33
43
|
end
|
|
34
44
|
|
|
@@ -80,6 +80,10 @@ module GOVUKDesignSystemFormBuilder
|
|
|
80
80
|
# * +:trust_error_messages+ call html_safe on error messages before they're
|
|
81
81
|
# rendered. This allows formatting markup to be used to change the display
|
|
82
82
|
# of the error message. Defaults to +false+
|
|
83
|
+
#
|
|
84
|
+
# * +:enable_nested_localisation+ scan the object name before building the
|
|
85
|
+
# localisation schema path to see if it's nested or not. The old behaviour
|
|
86
|
+
# can be restored by setting this option to +false+. Defaults to +true+
|
|
83
87
|
# ===
|
|
84
88
|
DEFAULTS = {
|
|
85
89
|
brand: 'govuk',
|
|
@@ -107,6 +111,10 @@ module GOVUKDesignSystemFormBuilder
|
|
|
107
111
|
|
|
108
112
|
enable_logger: true,
|
|
109
113
|
trust_error_messages: false,
|
|
114
|
+
|
|
115
|
+
# temporarily allow the new nested localisation functionality to be
|
|
116
|
+
# disabled
|
|
117
|
+
enable_nested_localisation: true,
|
|
110
118
|
}.freeze
|
|
111
119
|
|
|
112
120
|
DEFAULTS.each_key { |k| config_accessor(k) { DEFAULTS[k] } }
|
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:
|
|
4
|
+
version: 4.0.0a1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter Yates
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-01-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: html-attributes-utils
|
|
@@ -16,20 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
20
|
-
- - ">="
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: 0.9.2
|
|
19
|
+
version: '1'
|
|
23
20
|
type: :runtime
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
23
|
requirements:
|
|
27
24
|
- - "~>"
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.9.2
|
|
26
|
+
version: '1'
|
|
33
27
|
- !ruby/object:Gem::Dependency
|
|
34
28
|
name: actionview
|
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -140,14 +134,14 @@ dependencies:
|
|
|
140
134
|
requirements:
|
|
141
135
|
- - "~>"
|
|
142
136
|
- !ruby/object:Gem::Version
|
|
143
|
-
version: 4.
|
|
137
|
+
version: 4.9.0
|
|
144
138
|
type: :development
|
|
145
139
|
prerelease: false
|
|
146
140
|
version_requirements: !ruby/object:Gem::Requirement
|
|
147
141
|
requirements:
|
|
148
142
|
- - "~>"
|
|
149
143
|
- !ruby/object:Gem::Version
|
|
150
|
-
version: 4.
|
|
144
|
+
version: 4.9.0
|
|
151
145
|
- !ruby/object:Gem::Dependency
|
|
152
146
|
name: simplecov
|
|
153
147
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -362,7 +356,7 @@ metadata:
|
|
|
362
356
|
homepage_uri: https://govuk-form-builder.netlify.app
|
|
363
357
|
source_code_uri: https://github.com/DFE-Digital/govuk-formbuilder
|
|
364
358
|
github_repo: https://github.com/DFE-Digital/govuk-formbuilder
|
|
365
|
-
post_install_message:
|
|
359
|
+
post_install_message:
|
|
366
360
|
rdoc_options: []
|
|
367
361
|
require_paths:
|
|
368
362
|
- lib
|
|
@@ -373,12 +367,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
373
367
|
version: '0'
|
|
374
368
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
375
369
|
requirements:
|
|
376
|
-
- - "
|
|
370
|
+
- - ">"
|
|
377
371
|
- !ruby/object:Gem::Version
|
|
378
|
-
version:
|
|
372
|
+
version: 1.3.1
|
|
379
373
|
requirements: []
|
|
380
|
-
rubygems_version: 3.
|
|
381
|
-
signing_key:
|
|
374
|
+
rubygems_version: 3.2.33
|
|
375
|
+
signing_key:
|
|
382
376
|
specification_version: 4
|
|
383
377
|
summary: GOV.UK-compliant Rails form builder
|
|
384
378
|
test_files: []
|