govuk_design_system_formbuilder 3.3.0 → 4.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- 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/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 +18 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d47c45ad2ca56f3942aea3cd0f7d6e2f06a89ebfde5b94254ae56477dac2b611
|
4
|
+
data.tar.gz: 7f8ed5d840ab7b3f5c338ef7ad764b2f5eac7d6e1f35e0918521b385425b9a47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33328d0ac48cea098b5ae01024341b08733b4aef090d673b800e240295bcdc5902f686a000ad482be4bfcb439a7c98d07fda68e97d7951f72ad54aca5d05b9e8
|
7
|
+
data.tar.gz: 0276bb87a3cd4a20f26152ba72aa1b439cb05726a56c9770f65d2b1cbc417b5820cf5d02d580954faa3766aaac36029d21395688c13e394e6e6ed49775b1c546
|
data/README.md
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
[![Gem](https://img.shields.io/gem/dt/govuk_design_system_formbuilder?logo=rubygems)](https://rubygems.org/gems/govuk_design_system_formbuilder)
|
7
7
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/110136fb22341d3ba646/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk-formbuilder/test_coverage)
|
8
8
|
[![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk_design_system_formbuilder)](https://github.com/DFE-Digital/govuk-formbuilder/blob/main/LICENSE)
|
9
|
-
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.
|
9
|
+
[![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.5.0-brightgreen)](https://design-system.service.gov.uk)
|
10
10
|
[![Rails](https://img.shields.io/badge/Rails-6.1.7%20%E2%95%B1%207.0.4-E16D6D)](https://weblog.rubyonrails.org/releases/)
|
11
|
-
[![Ruby](https://img.shields.io/badge/Ruby-
|
11
|
+
[![Ruby](https://img.shields.io/badge/Ruby-3.0.5%20%20%E2%95%B1%203.1.3%20%20%E2%95%B1%203.2.0-E16D6D)](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
|
|
@@ -130,7 +130,7 @@ git config --global user.name "Julius Hibbert"
|
|
130
130
|
|
131
131
|
## Services using this library
|
132
132
|
|
133
|
-
Approximately [
|
133
|
+
Approximately [100 services use this library](https://github.com/DFE-Digital/govuk-formbuilder/network/dependents),
|
134
134
|
here are a few from the <abbr title="Department for Education">DfE</abbr>, <abbr title="Ministry of Justice">MoJ</abbr>, and
|
135
135
|
<abbr title="Department for Business, Energy & Industrial Strategy">BEIS</abbr>.
|
136
136
|
|
@@ -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
|
@@ -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.0rc1
|
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-04-13 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.10.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.10.0
|
151
145
|
- !ruby/object:Gem::Dependency
|
152
146
|
name: simplecov
|
153
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,28 +176,28 @@ dependencies:
|
|
182
176
|
requirements:
|
183
177
|
- - "~>"
|
184
178
|
- !ruby/object:Gem::Version
|
185
|
-
version:
|
179
|
+
version: 4.12.15
|
186
180
|
type: :development
|
187
181
|
prerelease: false
|
188
182
|
version_requirements: !ruby/object:Gem::Requirement
|
189
183
|
requirements:
|
190
184
|
- - "~>"
|
191
185
|
- !ruby/object:Gem::Version
|
192
|
-
version:
|
186
|
+
version: 4.12.15
|
193
187
|
- !ruby/object:Gem::Dependency
|
194
188
|
name: rouge
|
195
189
|
requirement: !ruby/object:Gem::Requirement
|
196
190
|
requirements:
|
197
191
|
- - "~>"
|
198
192
|
- !ruby/object:Gem::Version
|
199
|
-
version: 4.
|
193
|
+
version: 4.1.0
|
200
194
|
type: :development
|
201
195
|
prerelease: false
|
202
196
|
version_requirements: !ruby/object:Gem::Requirement
|
203
197
|
requirements:
|
204
198
|
- - "~>"
|
205
199
|
- !ruby/object:Gem::Version
|
206
|
-
version: 4.
|
200
|
+
version: 4.1.0
|
207
201
|
- !ruby/object:Gem::Dependency
|
208
202
|
name: rubypants
|
209
203
|
requirement: !ruby/object:Gem::Requirement
|
@@ -280,14 +274,14 @@ dependencies:
|
|
280
274
|
requirements:
|
281
275
|
- - "~>"
|
282
276
|
- !ruby/object:Gem::Version
|
283
|
-
version: 1.
|
277
|
+
version: 1.8.1
|
284
278
|
type: :development
|
285
279
|
prerelease: false
|
286
280
|
version_requirements: !ruby/object:Gem::Requirement
|
287
281
|
requirements:
|
288
282
|
- - "~>"
|
289
283
|
- !ruby/object:Gem::Version
|
290
|
-
version: 1.
|
284
|
+
version: 1.8.1
|
291
285
|
description: A Rails form builder that generates form inputs adhering to the GOV.UK
|
292
286
|
Design System
|
293
287
|
email:
|
@@ -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: []
|