katalyst-govuk-formbuilder 1.6.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d500045cb23ba6da9d6df55b1584249c2b95fadb8e44b0e8ea1fe63f58bbb5a1
|
4
|
+
data.tar.gz: 58dce6296ea70daee510c44a9c8bb403a3aed623cefff5496af5ff08cbe5b25c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37feec9e8a284f7ef6da32ea78543d6c525538485586a13cf7037f8ce8db0f7853111b1becbf8d26f9aeaacf7a164c243803d6adcbac9a4c6773eb5f717ee057
|
7
|
+
data.tar.gz: 956f29c704ddb6f99fe490142560945dc6f5738ec5af99601a7e83d1d1c963345c9720623007c0ca9c6c39215bb653af63e05b38f21d262b1535ddc2bfcf62de
|
@@ -30,15 +30,18 @@ module GOVUKDesignSystemFormBuilder
|
|
30
30
|
# hint: { text: 'You will not be able to proceed unless you do' }
|
31
31
|
#
|
32
32
|
def govuk_check_box_field(attribute_name, value = 1, unchecked_value = 0,
|
33
|
-
small:
|
33
|
+
small: true, hint: {}, label: {}, link_errors: false, **kwargs, &block)
|
34
34
|
govuk_check_boxes_fieldset(attribute_name, legend: nil, multiple: false, small:) do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
fieldset_context.pop # undo push from fieldset extension, labels should be bold unless already nested
|
36
|
+
checkbox = govuk_check_box(attribute_name, value, unchecked_value,
|
37
|
+
hint:,
|
38
|
+
label:,
|
39
|
+
link_errors:,
|
40
|
+
multiple: false,
|
41
|
+
exclusive: false,
|
42
|
+
**kwargs, &block)
|
43
|
+
fieldset_context.push attribute_name # restore push from fieldset
|
44
|
+
checkbox
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "govuk_design_system_formbuilder"
|
4
|
+
|
5
|
+
module Katalyst
|
6
|
+
module GOVUK
|
7
|
+
module Formbuilder
|
8
|
+
module Extensions
|
9
|
+
module Fieldset
|
10
|
+
def initialize(builder, object_name = nil, attribute_name = nil, &)
|
11
|
+
builder.fieldset_context << attribute_name
|
12
|
+
|
13
|
+
super
|
14
|
+
|
15
|
+
builder.fieldset_context.pop
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module GOVUKDesignSystemFormBuilder
|
24
|
+
module Builder
|
25
|
+
# Keep track of whether we are inside a fieldset
|
26
|
+
# This allows labels to default to bold ("s") normally but use the default otherwise
|
27
|
+
def fieldset_context
|
28
|
+
@fieldset_context ||= []
|
29
|
+
end
|
30
|
+
|
31
|
+
# Overwrite GOVUK default to set small to true
|
32
|
+
# @see GOVUKDesignSystemFormBuilder::Builder#govuk_collection_radio_buttons
|
33
|
+
def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil,
|
34
|
+
hint: {}, legend: {}, caption: {}, inline: false, small: true, bold_labels: nil,
|
35
|
+
include_hidden: config.default_collection_radio_buttons_include_hidden,
|
36
|
+
form_group: {}, **kwargs, &block)
|
37
|
+
Elements::Radios::Collection.new(
|
38
|
+
self,
|
39
|
+
object_name,
|
40
|
+
attribute_name,
|
41
|
+
collection,
|
42
|
+
value_method:,
|
43
|
+
text_method:,
|
44
|
+
hint_method:,
|
45
|
+
hint:,
|
46
|
+
legend:,
|
47
|
+
caption:,
|
48
|
+
inline:,
|
49
|
+
small:,
|
50
|
+
bold_labels:,
|
51
|
+
form_group:,
|
52
|
+
include_hidden:,
|
53
|
+
**kwargs,
|
54
|
+
&block
|
55
|
+
).html
|
56
|
+
end
|
57
|
+
|
58
|
+
# Overwrite GOVUK default to set small to true
|
59
|
+
# @see GOVUKDesignSystemFormBuilder::Builder#govuk_radio_buttons_fieldset
|
60
|
+
def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: true,
|
61
|
+
form_group: {}, **kwargs, &block)
|
62
|
+
Containers::RadioButtonsFieldset.new(self, object_name, attribute_name,
|
63
|
+
hint:, legend:, caption:, inline:, small:, form_group:,
|
64
|
+
**kwargs, &block).html
|
65
|
+
end
|
66
|
+
|
67
|
+
# Overwrite GOVUK default to set small to true
|
68
|
+
# @see GOVUKDesignSystemFormBuilder::Builder#govuk_collection_check_boxes
|
69
|
+
def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil,
|
70
|
+
hint: {}, legend: {}, caption: {}, small: true, form_group: {},
|
71
|
+
include_hidden: config.default_collection_check_boxes_include_hidden,
|
72
|
+
**kwargs, &block)
|
73
|
+
Elements::CheckBoxes::Collection.new(
|
74
|
+
self,
|
75
|
+
object_name,
|
76
|
+
attribute_name,
|
77
|
+
collection,
|
78
|
+
value_method:,
|
79
|
+
text_method:,
|
80
|
+
hint_method:,
|
81
|
+
hint:,
|
82
|
+
legend:,
|
83
|
+
caption:,
|
84
|
+
small:,
|
85
|
+
form_group:,
|
86
|
+
include_hidden:,
|
87
|
+
**kwargs,
|
88
|
+
&block
|
89
|
+
).html
|
90
|
+
end
|
91
|
+
|
92
|
+
# Overwrite GOVUK default to set small to true
|
93
|
+
# @see GOVUKDesignSystemFormBuilder::Builder#govuk_check_boxes_fieldset
|
94
|
+
def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: true, form_group: {},
|
95
|
+
multiple: true, **kwargs, &block)
|
96
|
+
Containers::CheckBoxesFieldset.new(
|
97
|
+
self,
|
98
|
+
object_name,
|
99
|
+
attribute_name,
|
100
|
+
hint:,
|
101
|
+
legend:,
|
102
|
+
caption:,
|
103
|
+
small:,
|
104
|
+
form_group:,
|
105
|
+
multiple:,
|
106
|
+
**kwargs,
|
107
|
+
&block
|
108
|
+
).html
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Extend Traits::Label set the default size to small for non-nested labels.
|
113
|
+
module Traits
|
114
|
+
module Label
|
115
|
+
private
|
116
|
+
|
117
|
+
def label_content
|
118
|
+
default = @builder.fieldset_context.count.positive? ? {} : { size: "s" }
|
119
|
+
|
120
|
+
case @label
|
121
|
+
when Hash
|
122
|
+
default.merge(@label)
|
123
|
+
when Proc
|
124
|
+
default.merge(content: @label)
|
125
|
+
else
|
126
|
+
fail(ArgumentError, %(label must be a Proc or Hash))
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Extend Elements::Label to add support for human_attribute_name as a fallback
|
133
|
+
module Elements
|
134
|
+
class Label
|
135
|
+
def retrieve_text(option_text, hidden)
|
136
|
+
text = option_text.presence ||
|
137
|
+
localised_text(:label).presence ||
|
138
|
+
human_attribute_name.presence ||
|
139
|
+
@attribute_name.to_s.humanize.capitalize.presence
|
140
|
+
|
141
|
+
if hidden
|
142
|
+
tag.span(text, class: %(#{brand}-visually-hidden))
|
143
|
+
else
|
144
|
+
text
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def human_attribute_name
|
149
|
+
return unless @object_name.present? && @attribute_name.present?
|
150
|
+
return unless @builder.object&.class.respond_to?(:human_attribute_name)
|
151
|
+
|
152
|
+
@builder.object.class.human_attribute_name(@attribute_name)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class Legend
|
157
|
+
def retrieve_text(supplied_text)
|
158
|
+
supplied_text.presence ||
|
159
|
+
localised_text(:legend).presence ||
|
160
|
+
human_attribute_name.presence ||
|
161
|
+
@attribute_name.to_s.humanize.capitalize.presence
|
162
|
+
end
|
163
|
+
|
164
|
+
def human_attribute_name
|
165
|
+
return unless @object_name.present? && @attribute_name.present?
|
166
|
+
return unless @builder.object&.class.respond_to?(:human_attribute_name)
|
167
|
+
|
168
|
+
@builder.object.class.human_attribute_name(@attribute_name)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
module Containers
|
174
|
+
class Fieldset
|
175
|
+
include Katalyst::GOVUK::Formbuilder::Extensions::Fieldset
|
176
|
+
end
|
177
|
+
|
178
|
+
class CheckBoxesFieldset
|
179
|
+
include Katalyst::GOVUK::Formbuilder::Extensions::Fieldset
|
180
|
+
end
|
181
|
+
|
182
|
+
class RadioButtonsFieldset
|
183
|
+
include Katalyst::GOVUK::Formbuilder::Extensions::Fieldset
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -5,6 +5,7 @@ require "govuk_design_system_formbuilder/elements/rich_text_area"
|
|
5
5
|
require "govuk_design_system_formbuilder/elements/check_box_field"
|
6
6
|
|
7
7
|
require "katalyst/govuk/formbuilder/engine"
|
8
|
+
require "katalyst/govuk/formbuilder/extensions"
|
8
9
|
require "katalyst/govuk/formbuilder/frontend"
|
9
10
|
|
10
11
|
module Katalyst
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-govuk-formbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_design_system_formbuilder
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/govuk_design_system_formbuilder/elements/rich_text_area.rb
|
46
46
|
- lib/katalyst/govuk/formbuilder.rb
|
47
47
|
- lib/katalyst/govuk/formbuilder/engine.rb
|
48
|
+
- lib/katalyst/govuk/formbuilder/extensions.rb
|
48
49
|
- lib/katalyst/govuk/formbuilder/frontend.rb
|
49
50
|
- vendor/assets/stylesheets/govuk-frontend/dist/govuk/_base.scss
|
50
51
|
- vendor/assets/stylesheets/govuk-frontend/dist/govuk/all.scss
|