metadata_presenter 2.16.9 → 2.16.12
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/app/models/metadata_presenter/component.rb +8 -0
- data/app/validators/metadata_presenter/base_validator.rb +10 -5
- data/app/validators/metadata_presenter/date_validator.rb +8 -0
- data/app/validators/metadata_presenter/maximum_validator.rb +3 -1
- data/app/validators/metadata_presenter/minimum_validator.rb +3 -1
- data/app/views/metadata_presenter/component/_textarea.html.erb +3 -3
- data/default_metadata/component/autocomplete.json +12 -0
- data/default_metadata/string/error.accept.json +1 -1
- data/default_metadata/string/error.date.json +1 -1
- data/default_metadata/string/error.date_after.json +1 -1
- data/default_metadata/string/error.date_before.json +1 -1
- data/default_metadata/string/error.max_length.json +1 -1
- data/default_metadata/string/error.max_word.json +1 -1
- data/default_metadata/string/error.maximum.json +1 -1
- data/default_metadata/string/error.min_length.json +1 -1
- data/default_metadata/string/error.min_word.json +1 -1
- data/default_metadata/string/error.minimum.json +1 -1
- data/default_metadata/string/error.number.json +1 -1
- data/default_metadata/string/error.required.json +2 -2
- data/default_metadata/string/error.virus_scan.json +1 -1
- data/lib/metadata_presenter/version.rb +1 -1
- data/schemas/component/autocomplete.json +17 -0
- data/schemas/definition/select.json +29 -0
- data/schemas/definition/select_option.json +34 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed9df3a1d56df6ff57746e7976d578741de8df0214f1080fbc661a087753bea
|
4
|
+
data.tar.gz: 85783ae10996111d01c523cff076ca0b82634cac855dfdf32f88665c5187a6d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c9fc79586eef3d60144b6bdb0093adf3a0ea07db6833a504d65a0bd96c474a66009a1900d071d51370db0857231430b7e18d2777bb7748d216b708f13bd5702
|
7
|
+
data.tar.gz: 27b1519b719d9f0c845271523e4afe4f89366e373868e2b18b10dd3d5360b49b22ba384789dd6a8c3cca46dab4599114a5845a8ecd47d833af8a832c1fcf1f7e
|
@@ -6,6 +6,10 @@ class MetadataPresenter::Component < MetadataPresenter::Metadata
|
|
6
6
|
'textarea' => 'string'
|
7
7
|
}.freeze
|
8
8
|
|
9
|
+
# Used for max_length and max_word validations.
|
10
|
+
# Threshold percentage at which the remaining count is shown
|
11
|
+
VALIDATION_STRING_LENGTH_THRESHOLD = 75
|
12
|
+
|
9
13
|
def to_partial_path
|
10
14
|
"metadata_presenter/component/#{type}"
|
11
15
|
end
|
@@ -46,6 +50,10 @@ class MetadataPresenter::Component < MetadataPresenter::Metadata
|
|
46
50
|
.keys
|
47
51
|
end
|
48
52
|
|
53
|
+
def validation_threshold
|
54
|
+
VALIDATION_STRING_LENGTH_THRESHOLD
|
55
|
+
end
|
56
|
+
|
49
57
|
private
|
50
58
|
|
51
59
|
def validation_bundle_key
|
@@ -75,10 +75,9 @@ module MetadataPresenter
|
|
75
75
|
# is not present
|
76
76
|
def default_error_message
|
77
77
|
default_error_message_key = "error.#{schema_key}"
|
78
|
-
default_message = Rails
|
79
|
-
|
80
|
-
|
81
|
-
.default_metadata[default_error_message_key]
|
78
|
+
default_message = Rails.application
|
79
|
+
.config
|
80
|
+
.default_metadata[default_error_message_key]
|
82
81
|
|
83
82
|
if default_message.present?
|
84
83
|
default_message['value'] % error_message_hash
|
@@ -116,10 +115,16 @@ module MetadataPresenter
|
|
116
115
|
def error_message_hash
|
117
116
|
{
|
118
117
|
control: component.humanised_title,
|
119
|
-
schema_key.to_sym =>
|
118
|
+
schema_key.to_sym => validation_value
|
120
119
|
}
|
121
120
|
end
|
122
121
|
|
122
|
+
# The validation configuration value
|
123
|
+
# Override if additional formatting of the value is required
|
124
|
+
def validation_value
|
125
|
+
component.validation[schema_key]
|
126
|
+
end
|
127
|
+
|
123
128
|
# Method signature to be overwrite in the subclass if you do not want to allow
|
124
129
|
# blank values. We should not allow blank when performing the required
|
125
130
|
# validation.
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module MetadataPresenter
|
2
2
|
class DateValidator < BaseValidator
|
3
|
+
DATE_STRING_VALIDATIONS = %w[date_after date_before].freeze
|
4
|
+
|
3
5
|
def invalid_answer?
|
4
6
|
Date.strptime(
|
5
7
|
"#{user_answer.year}-#{user_answer.month}-#{user_answer.day}",
|
@@ -10,5 +12,11 @@ module MetadataPresenter
|
|
10
12
|
rescue Date::Error
|
11
13
|
true
|
12
14
|
end
|
15
|
+
|
16
|
+
def validation_value
|
17
|
+
return unless schema_key.in?(DATE_STRING_VALIDATIONS)
|
18
|
+
|
19
|
+
Date.parse(component.validation[schema_key]).strftime('%d %m %Y')
|
20
|
+
end
|
13
21
|
end
|
14
22
|
end
|
@@ -6,8 +6,8 @@
|
|
6
6
|
text: component.hint
|
7
7
|
},
|
8
8
|
name: "answers[#{component.name}]",
|
9
|
-
max_chars: component.
|
10
|
-
max_words: component.
|
11
|
-
threshold: component.
|
9
|
+
max_chars: component.validation['max_length'],
|
10
|
+
max_words: component.validation['max_word'],
|
11
|
+
threshold: component.validation_threshold,
|
12
12
|
rows: component.rows
|
13
13
|
%>
|
@@ -2,5 +2,5 @@
|
|
2
2
|
"_id": "error.max_length",
|
3
3
|
"_type": "string.error",
|
4
4
|
"description": "Input (string) is too long",
|
5
|
-
"value": "Your answer for
|
5
|
+
"value": "Your answer for \"%{control}\" must be %{max_length} characters or fewer"
|
6
6
|
}
|
@@ -2,5 +2,5 @@
|
|
2
2
|
"_id": "error.max_word",
|
3
3
|
"_type": "string.error",
|
4
4
|
"description": "Input (number) is higher than the maximum number of words allowed",
|
5
|
-
"value": "
|
5
|
+
"value": "Your answer for \"%{control}\" must be %{max_word} words or fewer"
|
6
6
|
}
|
@@ -2,5 +2,5 @@
|
|
2
2
|
"_id": "error.min_length",
|
3
3
|
"_type": "string.error",
|
4
4
|
"description": "Input (string) is too short",
|
5
|
-
"value": "Your answer for
|
5
|
+
"value": "Your answer for \"%{control}\" must be %{min_length} characters or more"
|
6
6
|
}
|
@@ -2,5 +2,5 @@
|
|
2
2
|
"_id": "error.min_word",
|
3
3
|
"_type": "string.error",
|
4
4
|
"description": "Input (number) is lower than the minimum number of words allowed",
|
5
|
-
"value": "
|
5
|
+
"value": "Your answer for \"%{control}\" must be %{min_word} words or more"
|
6
6
|
}
|
@@ -2,6 +2,6 @@
|
|
2
2
|
"_id": "error.required",
|
3
3
|
"_type": "string.error",
|
4
4
|
"description": "Input is required",
|
5
|
-
"value": "Enter an answer for %{control}",
|
6
|
-
"value:cy": "Rhowch ateb i {control}"
|
5
|
+
"value": "Enter an answer for \"%{control}\"",
|
6
|
+
"value:cy": "Rhowch ateb i \"{control}\""
|
7
7
|
}
|
@@ -2,6 +2,6 @@
|
|
2
2
|
"_id": "error.virus_scan",
|
3
3
|
"_type": "string.error",
|
4
4
|
"description": "File uploaded contains virus",
|
5
|
-
"value": "%{control} was not uploaded successfully because it contains a virus"
|
5
|
+
"value": "\"%{control}\" was not uploaded successfully because it contains a virus"
|
6
6
|
}
|
7
7
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/autocomplete",
|
3
|
+
"_name": "autocomplete",
|
4
|
+
"title": "Autocomplete",
|
5
|
+
"description": "Let users select one option from an auto-completing list",
|
6
|
+
"type": "object",
|
7
|
+
"allOf": [
|
8
|
+
{
|
9
|
+
"$ref": "definition.select"
|
10
|
+
}
|
11
|
+
],
|
12
|
+
"properties": {
|
13
|
+
"_type": {
|
14
|
+
"const": "autocomplete"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/definition/select",
|
3
|
+
"_name": "definition.select",
|
4
|
+
"title": "Select component definition",
|
5
|
+
"allOf": [
|
6
|
+
{
|
7
|
+
"$ref": "definition.field"
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"$ref": "definition.width_class.input"
|
11
|
+
}
|
12
|
+
],
|
13
|
+
"properties": {
|
14
|
+
"items": {
|
15
|
+
"title": "Options",
|
16
|
+
"description": "Items that users can select",
|
17
|
+
"type": "array",
|
18
|
+
"items": {
|
19
|
+
"$ref": "definition.select_option"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"required": [
|
24
|
+
"items"
|
25
|
+
],
|
26
|
+
"category": [
|
27
|
+
"select"
|
28
|
+
]
|
29
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"$id": "http://gov.uk/schema/v1.0.0/definition/select_option",
|
3
|
+
"_name": "definition.select_option",
|
4
|
+
"title": "Select option",
|
5
|
+
"description": "Component that provides a select option",
|
6
|
+
"type": "object",
|
7
|
+
"properties": {
|
8
|
+
"_type": {
|
9
|
+
"const": "select_option"
|
10
|
+
},
|
11
|
+
"text": {
|
12
|
+
"title": "Option text",
|
13
|
+
"description": "Text displayed to users for that option",
|
14
|
+
"type": "string",
|
15
|
+
"content": true
|
16
|
+
},
|
17
|
+
"value": {
|
18
|
+
"title": "Option value",
|
19
|
+
"description": "Value assigned when users select option",
|
20
|
+
"type": "string"
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"allOf": [
|
24
|
+
{
|
25
|
+
"$ref": "definition.component"
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"required": [
|
29
|
+
"value"
|
30
|
+
],
|
31
|
+
"category": [
|
32
|
+
"select_option"
|
33
|
+
]
|
34
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metadata_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.16.
|
4
|
+
version: 2.16.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MoJ Forms
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_design_system_formbuilder
|
@@ -365,6 +365,7 @@ files:
|
|
365
365
|
- config/initializers/schemas.rb
|
366
366
|
- config/initializers/supported_components.rb
|
367
367
|
- config/routes.rb
|
368
|
+
- default_metadata/component/autocomplete.json
|
368
369
|
- default_metadata/component/checkboxes.json
|
369
370
|
- default_metadata/component/content.json
|
370
371
|
- default_metadata/component/date.json
|
@@ -448,6 +449,7 @@ files:
|
|
448
449
|
- lib/metadata_presenter/test_helpers.rb
|
449
450
|
- lib/metadata_presenter/version.rb
|
450
451
|
- lib/tasks/metadata_presenter_tasks.rake
|
452
|
+
- schemas/component/autocomplete.json
|
451
453
|
- schemas/component/checkboxes.json
|
452
454
|
- schemas/component/content.json
|
453
455
|
- schemas/component/date.json
|
@@ -493,6 +495,8 @@ files:
|
|
493
495
|
- schemas/definition/page.json
|
494
496
|
- schemas/definition/radio.json
|
495
497
|
- schemas/definition/repeatable.json
|
498
|
+
- schemas/definition/select.json
|
499
|
+
- schemas/definition/select_option.json
|
496
500
|
- schemas/definition/width_class.input.json
|
497
501
|
- schemas/definition/width_class.json
|
498
502
|
- schemas/errors/errors.json
|