@defra/forms-engine-plugin 4.0.6 → 4.0.8
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.
- package/.public/stylesheets/application.min.css +1 -1
- package/.public/stylesheets/application.min.css.map +1 -1
- package/.server/client/stylesheets/_location-input.scss +60 -0
- package/.server/client/stylesheets/application.scss +1 -0
- package/.server/client/stylesheets/shared.scss +1 -0
- package/.server/server/forms/components.json +7 -0
- package/.server/server/forms/register-as-a-unicorn-breeder.yaml +40 -1
- package/.server/server/plugins/engine/components/ComponentBase.d.ts +2 -2
- package/.server/server/plugins/engine/components/ComponentBase.js.map +1 -1
- package/.server/server/plugins/engine/components/ComponentCollection.js.map +1 -1
- package/.server/server/plugins/engine/components/DeclarationField.d.ts +81 -0
- package/.server/server/plugins/engine/components/DeclarationField.js +123 -0
- package/.server/server/plugins/engine/components/DeclarationField.js.map +1 -0
- package/.server/server/plugins/engine/components/EastingNorthingField.d.ts +121 -0
- package/.server/server/plugins/engine/components/EastingNorthingField.js +166 -0
- package/.server/server/plugins/engine/components/EastingNorthingField.js.map +1 -0
- package/.server/server/plugins/engine/components/LatLongField.d.ts +121 -0
- package/.server/server/plugins/engine/components/LatLongField.js +164 -0
- package/.server/server/plugins/engine/components/LatLongField.js.map +1 -0
- package/.server/server/plugins/engine/components/LocationFieldBase.d.ts +134 -0
- package/.server/server/plugins/engine/components/LocationFieldBase.js +85 -0
- package/.server/server/plugins/engine/components/LocationFieldBase.js.map +1 -0
- package/.server/server/plugins/engine/components/LocationFieldHelpers.d.ts +108 -0
- package/.server/server/plugins/engine/components/LocationFieldHelpers.js +96 -0
- package/.server/server/plugins/engine/components/LocationFieldHelpers.js.map +1 -0
- package/.server/server/plugins/engine/components/NationalGridFieldNumberField.d.ts +19 -0
- package/.server/server/plugins/engine/components/NationalGridFieldNumberField.js +40 -0
- package/.server/server/plugins/engine/components/NationalGridFieldNumberField.js.map +1 -0
- package/.server/server/plugins/engine/components/OsGridRefField.d.ts +19 -0
- package/.server/server/plugins/engine/components/OsGridRefField.js +56 -0
- package/.server/server/plugins/engine/components/OsGridRefField.js.map +1 -0
- package/.server/server/plugins/engine/components/helpers/components.d.ts +3 -4
- package/.server/server/plugins/engine/components/helpers/components.js +24 -29
- package/.server/server/plugins/engine/components/helpers/components.js.map +1 -1
- package/.server/server/plugins/engine/components/index.d.ts +5 -0
- package/.server/server/plugins/engine/components/index.js +5 -0
- package/.server/server/plugins/engine/components/index.js.map +1 -1
- package/.server/server/plugins/engine/components/markdownParser.d.ts +2 -0
- package/.server/server/plugins/engine/components/markdownParser.js +28 -0
- package/.server/server/plugins/engine/components/markdownParser.js.map +1 -0
- package/.server/server/plugins/engine/components/types.d.ts +10 -0
- package/.server/server/plugins/engine/components/types.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/helpers/pages.js +7 -0
- package/.server/server/plugins/engine/pageControllers/helpers/pages.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/validationOptions.js +1 -0
- package/.server/server/plugins/engine/pageControllers/validationOptions.js.map +1 -1
- package/.server/server/plugins/engine/types/index.d.ts +1 -1
- package/.server/server/plugins/engine/types/index.js.map +1 -1
- package/.server/server/plugins/engine/types.d.ts +2 -2
- package/.server/server/plugins/engine/types.js.map +1 -1
- package/.server/server/plugins/engine/views/components/_location-field-base.html +53 -0
- package/.server/server/plugins/engine/views/components/declarationfield.html +14 -0
- package/.server/server/plugins/engine/views/components/eastingnorthingfield.html +5 -0
- package/.server/server/plugins/engine/views/components/latlongfield.html +5 -0
- package/.server/server/plugins/engine/views/components/nationalgridfieldnumberfield.html +13 -0
- package/.server/server/plugins/engine/views/components/osgridreffield.html +13 -0
- package/.server/server/plugins/nunjucks/filters/field.d.ts +1 -1
- package/.server/server/plugins/nunjucks/filters/index.d.ts +1 -0
- package/.server/server/plugins/nunjucks/filters/index.js +1 -0
- package/.server/server/plugins/nunjucks/filters/index.js.map +1 -1
- package/.server/server/plugins/nunjucks/filters/merge.d.ts +7 -0
- package/.server/server/plugins/nunjucks/filters/merge.js +16 -0
- package/.server/server/plugins/nunjucks/filters/merge.js.map +1 -0
- package/.server/server/plugins/nunjucks/filters/merge.test.js +19 -0
- package/.server/server/plugins/nunjucks/filters/merge.test.js.map +1 -0
- package/package.json +3 -3
- package/src/client/stylesheets/_location-input.scss +60 -0
- package/src/client/stylesheets/application.scss +1 -0
- package/src/client/stylesheets/shared.scss +1 -0
- package/src/server/forms/components.json +7 -0
- package/src/server/forms/page-events.yaml +1 -1
- package/src/server/forms/register-as-a-unicorn-breeder.yaml +40 -1
- package/src/server/index.test.ts +1 -0
- package/src/server/plugins/engine/components/ComponentBase.ts +2 -1
- package/src/server/plugins/engine/components/ComponentCollection.ts +1 -0
- package/src/server/plugins/engine/components/DeclarationField.test.ts +426 -0
- package/src/server/plugins/engine/components/DeclarationField.ts +167 -0
- package/src/server/plugins/engine/components/EastingNorthingField.test.ts +665 -0
- package/src/server/plugins/engine/components/EastingNorthingField.ts +224 -0
- package/src/server/plugins/engine/components/LatLongField.test.ts +700 -0
- package/src/server/plugins/engine/components/LatLongField.ts +213 -0
- package/src/server/plugins/engine/components/LocationFieldBase.test.ts +253 -0
- package/src/server/plugins/engine/components/LocationFieldBase.ts +152 -0
- package/src/server/plugins/engine/components/LocationFieldHelpers.test.ts +338 -0
- package/src/server/plugins/engine/components/LocationFieldHelpers.ts +123 -0
- package/src/server/plugins/engine/components/NationalGridFieldNumberField.test.ts +438 -0
- package/src/server/plugins/engine/components/NationalGridFieldNumberField.ts +52 -0
- package/src/server/plugins/engine/components/OsGridRefField.test.ts +469 -0
- package/src/server/plugins/engine/components/OsGridRefField.ts +71 -0
- package/src/server/plugins/engine/components/helpers/components.test.ts +270 -0
- package/src/server/plugins/engine/components/helpers/components.ts +44 -47
- package/src/server/plugins/engine/components/helpers/helpers.test.ts +71 -1
- package/src/server/plugins/engine/components/index.ts +5 -0
- package/src/server/plugins/engine/components/markdownParser.ts +40 -0
- package/src/server/plugins/engine/components/types.ts +14 -0
- package/src/server/plugins/engine/models/SummaryViewModel.test.ts +76 -3
- package/src/server/plugins/engine/models/SummaryViewModel.ts +5 -1
- package/src/server/plugins/engine/outputFormatters/adapter/v1.location.test.ts +356 -0
- package/src/server/plugins/engine/pageControllers/helpers/helpers.test.ts +4 -0
- package/src/server/plugins/engine/pageControllers/helpers/pages.ts +8 -0
- package/src/server/plugins/engine/pageControllers/validationOptions.ts +4 -0
- package/src/server/plugins/engine/types/index.ts +2 -0
- package/src/server/plugins/engine/types.ts +4 -0
- package/src/server/plugins/engine/views/components/_location-field-base.html +53 -0
- package/src/server/plugins/engine/views/components/declarationfield.html +14 -0
- package/src/server/plugins/engine/views/components/eastingnorthingfield.html +5 -0
- package/src/server/plugins/engine/views/components/latlongfield.html +5 -0
- package/src/server/plugins/engine/views/components/nationalgridfieldnumberfield.html +13 -0
- package/src/server/plugins/engine/views/components/osgridreffield.html +13 -0
- package/src/server/plugins/nunjucks/filters/index.js +1 -0
- package/src/server/plugins/nunjucks/filters/merge.js +16 -0
- package/src/server/plugins/nunjucks/filters/merge.test.js +15 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { ComponentType } from '@defra/forms-model';
|
|
2
|
+
import { ComponentCollection } from "./ComponentCollection.js";
|
|
3
|
+
import { FormComponent, isFormState } from "./FormComponent.js";
|
|
4
|
+
import { createLocationFieldValidator, getLocationFieldViewModel } from "./LocationFieldHelpers.js";
|
|
5
|
+
import { NumberField } from "./NumberField.js";
|
|
6
|
+
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
7
|
+
import { convertToLanguageMessages } from "../../../utils/type-utils.js";
|
|
8
|
+
|
|
9
|
+
// British National Grid coordinate limits
|
|
10
|
+
const DEFAULT_EASTING_MIN = 0;
|
|
11
|
+
const DEFAULT_EASTING_MAX = 70000;
|
|
12
|
+
const DEFAULT_NORTHING_MIN = 0;
|
|
13
|
+
const DEFAULT_NORTHING_MAX = 1300000;
|
|
14
|
+
export class EastingNorthingField extends FormComponent {
|
|
15
|
+
constructor(def, props) {
|
|
16
|
+
super(def, props);
|
|
17
|
+
const {
|
|
18
|
+
name,
|
|
19
|
+
options,
|
|
20
|
+
schema
|
|
21
|
+
} = def;
|
|
22
|
+
const isRequired = options.required !== false;
|
|
23
|
+
const eastingMin = schema?.easting?.min ?? DEFAULT_EASTING_MIN;
|
|
24
|
+
const eastingMax = schema?.easting?.max ?? DEFAULT_EASTING_MAX;
|
|
25
|
+
const northingMin = schema?.northing?.min ?? DEFAULT_NORTHING_MIN;
|
|
26
|
+
const northingMax = schema?.northing?.max ?? DEFAULT_NORTHING_MAX;
|
|
27
|
+
const customValidationMessages = convertToLanguageMessages({
|
|
28
|
+
'any.required': messageTemplate.objectMissing,
|
|
29
|
+
'number.base': messageTemplate.objectMissing,
|
|
30
|
+
'number.min': `{{#label}} for ${this.title} must be between {{#limit}} and ${eastingMax}`,
|
|
31
|
+
'number.max': `{{#label}} for ${this.title} must be between ${eastingMin} and {{#limit}}`,
|
|
32
|
+
'number.precision': `{{#label}} for ${this.title} must be between 1 and 5 digits`,
|
|
33
|
+
'number.integer': `{{#label}} for ${this.title} must be between 1 and 5 digits`,
|
|
34
|
+
'number.unsafe': `{{#label}} for ${this.title} must be between 1 and 5 digits`
|
|
35
|
+
});
|
|
36
|
+
const northingValidationMessages = convertToLanguageMessages({
|
|
37
|
+
'any.required': messageTemplate.objectMissing,
|
|
38
|
+
'number.base': messageTemplate.objectMissing,
|
|
39
|
+
'number.min': `{{#label}} for ${this.title} must be between {{#limit}} and ${northingMax}`,
|
|
40
|
+
'number.max': `{{#label}} for ${this.title} must be between ${northingMin} and {{#limit}}`,
|
|
41
|
+
'number.precision': `{{#label}} for ${this.title} must be between 1 and 7 digits`,
|
|
42
|
+
'number.integer': `{{#label}} for ${this.title} must be between 1 and 7 digits`,
|
|
43
|
+
'number.unsafe': `{{#label}} for ${this.title} must be between 1 and 7 digits`
|
|
44
|
+
});
|
|
45
|
+
this.collection = new ComponentCollection([{
|
|
46
|
+
type: ComponentType.NumberField,
|
|
47
|
+
name: `${name}__easting`,
|
|
48
|
+
title: 'Easting',
|
|
49
|
+
schema: {
|
|
50
|
+
min: eastingMin,
|
|
51
|
+
max: eastingMax,
|
|
52
|
+
precision: 0
|
|
53
|
+
},
|
|
54
|
+
options: {
|
|
55
|
+
required: isRequired,
|
|
56
|
+
optionalText: true,
|
|
57
|
+
classes: 'govuk-input--width-10',
|
|
58
|
+
customValidationMessages
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
type: ComponentType.NumberField,
|
|
62
|
+
name: `${name}__northing`,
|
|
63
|
+
title: 'Northing',
|
|
64
|
+
schema: {
|
|
65
|
+
min: northingMin,
|
|
66
|
+
max: northingMax,
|
|
67
|
+
precision: 0
|
|
68
|
+
},
|
|
69
|
+
options: {
|
|
70
|
+
required: isRequired,
|
|
71
|
+
optionalText: true,
|
|
72
|
+
classes: 'govuk-input--width-10',
|
|
73
|
+
customValidationMessages: northingValidationMessages
|
|
74
|
+
}
|
|
75
|
+
}], {
|
|
76
|
+
...props,
|
|
77
|
+
parent: this
|
|
78
|
+
}, {
|
|
79
|
+
custom: getValidatorEastingNorthing(this),
|
|
80
|
+
peers: [`${name}__easting`, `${name}__northing`]
|
|
81
|
+
});
|
|
82
|
+
this.options = options;
|
|
83
|
+
this.formSchema = this.collection.formSchema;
|
|
84
|
+
this.stateSchema = this.collection.stateSchema;
|
|
85
|
+
}
|
|
86
|
+
getFormValueFromState(state) {
|
|
87
|
+
const value = super.getFormValueFromState(state);
|
|
88
|
+
return EastingNorthingField.isEastingNorthing(value) ? value : undefined;
|
|
89
|
+
}
|
|
90
|
+
getDisplayStringFromFormValue(value) {
|
|
91
|
+
if (!value) {
|
|
92
|
+
return '';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// CYA page format: <<northingvalue, eastingvalue>>
|
|
96
|
+
return `${value.northing}, ${value.easting}`;
|
|
97
|
+
}
|
|
98
|
+
getDisplayStringFromState(state) {
|
|
99
|
+
const value = this.getFormValueFromState(state);
|
|
100
|
+
return this.getDisplayStringFromFormValue(value);
|
|
101
|
+
}
|
|
102
|
+
getContextValueFromFormValue(value) {
|
|
103
|
+
if (!value) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Output format: Northing: <<entry>>\nEasting: <<entry>>
|
|
108
|
+
return `Northing: ${value.northing}\nEasting: ${value.easting}`;
|
|
109
|
+
}
|
|
110
|
+
getContextValueFromState(state) {
|
|
111
|
+
const value = this.getFormValueFromState(state);
|
|
112
|
+
return this.getContextValueFromFormValue(value);
|
|
113
|
+
}
|
|
114
|
+
getViewModel(payload, errors) {
|
|
115
|
+
const viewModel = super.getViewModel(payload, errors);
|
|
116
|
+
return getLocationFieldViewModel(this, viewModel, payload, errors);
|
|
117
|
+
}
|
|
118
|
+
isState(value) {
|
|
119
|
+
return EastingNorthingField.isEastingNorthing(value);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* For error preview page that shows all possible errors on a component
|
|
124
|
+
*/
|
|
125
|
+
getAllPossibleErrors() {
|
|
126
|
+
return EastingNorthingField.getAllPossibleErrors();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Static version of getAllPossibleErrors that doesn't require a component instance.
|
|
131
|
+
*/
|
|
132
|
+
static getAllPossibleErrors() {
|
|
133
|
+
return {
|
|
134
|
+
baseErrors: [{
|
|
135
|
+
type: 'required',
|
|
136
|
+
template: messageTemplate.required
|
|
137
|
+
}, {
|
|
138
|
+
type: 'eastingFormat',
|
|
139
|
+
template: 'Easting for [short description] must be between 1 and 5 digits'
|
|
140
|
+
}, {
|
|
141
|
+
type: 'northingFormat',
|
|
142
|
+
template: 'Northing for [short description] must be between 1 and 7 digits'
|
|
143
|
+
}],
|
|
144
|
+
advancedSettingsErrors: [{
|
|
145
|
+
type: 'eastingMin',
|
|
146
|
+
template: `Easting for [short description] must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`
|
|
147
|
+
}, {
|
|
148
|
+
type: 'eastingMax',
|
|
149
|
+
template: `Easting for [short description] must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`
|
|
150
|
+
}, {
|
|
151
|
+
type: 'northingMin',
|
|
152
|
+
template: `Northing for [short description] must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`
|
|
153
|
+
}, {
|
|
154
|
+
type: 'northingMax',
|
|
155
|
+
template: `Northing for [short description] must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`
|
|
156
|
+
}]
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
static isEastingNorthing(value) {
|
|
160
|
+
return isFormState(value) && NumberField.isNumber(value.easting) && NumberField.isNumber(value.northing);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function getValidatorEastingNorthing(component) {
|
|
164
|
+
return createLocationFieldValidator(component);
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=EastingNorthingField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EastingNorthingField.js","names":["ComponentType","ComponentCollection","FormComponent","isFormState","createLocationFieldValidator","getLocationFieldViewModel","NumberField","messageTemplate","convertToLanguageMessages","DEFAULT_EASTING_MIN","DEFAULT_EASTING_MAX","DEFAULT_NORTHING_MIN","DEFAULT_NORTHING_MAX","EastingNorthingField","constructor","def","props","name","options","schema","isRequired","required","eastingMin","easting","min","eastingMax","max","northingMin","northing","northingMax","customValidationMessages","objectMissing","title","northingValidationMessages","collection","type","precision","optionalText","classes","parent","custom","getValidatorEastingNorthing","peers","formSchema","stateSchema","getFormValueFromState","state","value","isEastingNorthing","undefined","getDisplayStringFromFormValue","getDisplayStringFromState","getContextValueFromFormValue","getContextValueFromState","getViewModel","payload","errors","viewModel","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isNumber","component"],"sources":["../../../../../src/server/plugins/engine/components/EastingNorthingField.ts"],"sourcesContent":["import {\n ComponentType,\n type EastingNorthingFieldComponent\n} from '@defra/forms-model'\nimport { type LanguageMessages, type ObjectSchema } from 'joi'\n\nimport { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport {\n FormComponent,\n isFormState\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport {\n createLocationFieldValidator,\n getLocationFieldViewModel\n} from '~/src/server/plugins/engine/components/LocationFieldHelpers.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport { type EastingNorthingState } from '~/src/server/plugins/engine/components/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\n// British National Grid coordinate limits\nconst DEFAULT_EASTING_MIN = 0\nconst DEFAULT_EASTING_MAX = 70000\nconst DEFAULT_NORTHING_MIN = 0\nconst DEFAULT_NORTHING_MAX = 1300000\n\nexport class EastingNorthingField extends FormComponent {\n declare options: EastingNorthingFieldComponent['options']\n declare formSchema: ObjectSchema<FormPayload>\n declare stateSchema: ObjectSchema<FormState>\n declare collection: ComponentCollection\n\n constructor(\n def: EastingNorthingFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { name, options, schema } = def\n\n const isRequired = options.required !== false\n\n const eastingMin = schema?.easting?.min ?? DEFAULT_EASTING_MIN\n const eastingMax = schema?.easting?.max ?? DEFAULT_EASTING_MAX\n const northingMin = schema?.northing?.min ?? DEFAULT_NORTHING_MIN\n const northingMax = schema?.northing?.max ?? DEFAULT_NORTHING_MAX\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n 'any.required': messageTemplate.objectMissing,\n 'number.base': messageTemplate.objectMissing,\n 'number.min': `{{#label}} for ${this.title} must be between {{#limit}} and ${eastingMax}`,\n 'number.max': `{{#label}} for ${this.title} must be between ${eastingMin} and {{#limit}}`,\n 'number.precision': `{{#label}} for ${this.title} must be between 1 and 5 digits`,\n 'number.integer': `{{#label}} for ${this.title} must be between 1 and 5 digits`,\n 'number.unsafe': `{{#label}} for ${this.title} must be between 1 and 5 digits`\n })\n\n const northingValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n 'any.required': messageTemplate.objectMissing,\n 'number.base': messageTemplate.objectMissing,\n 'number.min': `{{#label}} for ${this.title} must be between {{#limit}} and ${northingMax}`,\n 'number.max': `{{#label}} for ${this.title} must be between ${northingMin} and {{#limit}}`,\n 'number.precision': `{{#label}} for ${this.title} must be between 1 and 7 digits`,\n 'number.integer': `{{#label}} for ${this.title} must be between 1 and 7 digits`,\n 'number.unsafe': `{{#label}} for ${this.title} must be between 1 and 7 digits`\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__easting`,\n title: 'Easting',\n schema: { min: eastingMin, max: eastingMax, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-10',\n customValidationMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__northing`,\n title: 'Northing',\n schema: { min: northingMin, max: northingMax, precision: 0 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-10',\n customValidationMessages: northingValidationMessages\n }\n }\n ],\n { ...props, parent: this },\n {\n custom: getValidatorEastingNorthing(this),\n peers: [`${name}__easting`, `${name}__northing`]\n }\n )\n\n this.options = options\n this.formSchema = this.collection.formSchema\n this.stateSchema = this.collection.stateSchema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const value = super.getFormValueFromState(state)\n return EastingNorthingField.isEastingNorthing(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(\n value: EastingNorthingState | undefined\n ): string {\n if (!value) {\n return ''\n }\n\n // CYA page format: <<northingvalue, eastingvalue>>\n return `${value.northing}, ${value.easting}`\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n return this.getDisplayStringFromFormValue(value)\n }\n\n getContextValueFromFormValue(\n value: EastingNorthingState | undefined\n ): string | null {\n if (!value) {\n return null\n }\n\n // Output format: Northing: <<entry>>\\nEasting: <<entry>>\n return `Northing: ${value.northing}\\nEasting: ${value.easting}`\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(value)\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const viewModel = super.getViewModel(payload, errors)\n return getLocationFieldViewModel(this, viewModel, payload, errors)\n }\n\n isState(value?: FormStateValue | FormState) {\n return EastingNorthingField.isEastingNorthing(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return EastingNorthingField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n {\n type: 'eastingFormat',\n template:\n 'Easting for [short description] must be between 1 and 5 digits'\n },\n {\n type: 'northingFormat',\n template:\n 'Northing for [short description] must be between 1 and 7 digits'\n }\n ],\n advancedSettingsErrors: [\n {\n type: 'eastingMin',\n template: `Easting for [short description] must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`\n },\n {\n type: 'eastingMax',\n template: `Easting for [short description] must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`\n },\n {\n type: 'northingMin',\n template: `Northing for [short description] must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`\n },\n {\n type: 'northingMax',\n template: `Northing for [short description] must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`\n }\n ]\n }\n }\n\n static isEastingNorthing(\n value?: FormStateValue | FormState\n ): value is EastingNorthingState {\n return (\n isFormState(value) &&\n NumberField.isNumber(value.easting) &&\n NumberField.isNumber(value.northing)\n )\n }\n}\n\nexport function getValidatorEastingNorthing(component: EastingNorthingField) {\n return createLocationFieldValidator(component)\n}\n"],"mappings":"AAAA,SACEA,aAAa,QAER,oBAAoB;AAG3B,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW;AAEb,SACEC,4BAA4B,EAC5BC,yBAAyB;AAE3B,SAASC,WAAW;AAEpB,SAASC,eAAe;AASxB,SAASC,yBAAyB;;AAElC;AACA,MAAMC,mBAAmB,GAAG,CAAC;AAC7B,MAAMC,mBAAmB,GAAG,KAAK;AACjC,MAAMC,oBAAoB,GAAG,CAAC;AAC9B,MAAMC,oBAAoB,GAAG,OAAO;AAEpC,OAAO,MAAMC,oBAAoB,SAASX,aAAa,CAAC;EAMtDY,WAAWA,CACTC,GAAkC,EAClCC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,IAAI;MAAEC,OAAO;MAAEC;IAAO,CAAC,GAAGJ,GAAG;IAErC,MAAMK,UAAU,GAAGF,OAAO,CAACG,QAAQ,KAAK,KAAK;IAE7C,MAAMC,UAAU,GAAGH,MAAM,EAAEI,OAAO,EAAEC,GAAG,IAAIf,mBAAmB;IAC9D,MAAMgB,UAAU,GAAGN,MAAM,EAAEI,OAAO,EAAEG,GAAG,IAAIhB,mBAAmB;IAC9D,MAAMiB,WAAW,GAAGR,MAAM,EAAES,QAAQ,EAAEJ,GAAG,IAAIb,oBAAoB;IACjE,MAAMkB,WAAW,GAAGV,MAAM,EAAES,QAAQ,EAAEF,GAAG,IAAId,oBAAoB;IAEjE,MAAMkB,wBAA0C,GAC9CtB,yBAAyB,CAAC;MACxB,cAAc,EAAED,eAAe,CAACwB,aAAa;MAC7C,aAAa,EAAExB,eAAe,CAACwB,aAAa;MAC5C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oDlD,oBAAoB,QAAQC,oBAAoB;MAChH,CAAC,EACD;QACEuB,IAAI,EAAE,aAAa;QACnB0B,QAAQ,EAAE,oDAAoDlD,oBAAoB,QAAQC,oBAAoB;MAChH,CAAC;IAEL,CAAC;EACH;EAEA,OAAOoC,iBAAiBA,CACtBD,KAAkC,EACH;IAC/B,OACE5C,WAAW,CAAC4C,KAAK,CAAC,IAClBzC,WAAW,CAACyD,QAAQ,CAAChB,KAAK,CAACxB,OAAO,CAAC,IACnCjB,WAAW,CAACyD,QAAQ,CAAChB,KAAK,CAACnB,QAAQ,CAAC;EAExC;AACF;AAEA,OAAO,SAASa,2BAA2BA,CAACuB,SAA+B,EAAE;EAC3E,OAAO5D,4BAA4B,CAAC4D,SAAS,CAAC;AAChD","ignoreList":[]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { type LatLongFieldComponent } from '@defra/forms-model';
|
|
2
|
+
import { type ObjectSchema } from 'joi';
|
|
3
|
+
import { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js';
|
|
4
|
+
import { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js';
|
|
5
|
+
import { type LatLongState } from '~/src/server/plugins/engine/components/types.js';
|
|
6
|
+
import { type ErrorMessageTemplateList, type FormPayload, type FormState, type FormStateValue, type FormSubmissionError, type FormSubmissionState } from '~/src/server/plugins/engine/types.js';
|
|
7
|
+
export declare class LatLongField extends FormComponent {
|
|
8
|
+
options: LatLongFieldComponent['options'];
|
|
9
|
+
formSchema: ObjectSchema<FormPayload>;
|
|
10
|
+
stateSchema: ObjectSchema<FormState>;
|
|
11
|
+
collection: ComponentCollection;
|
|
12
|
+
constructor(def: LatLongFieldComponent, props: ConstructorParameters<typeof FormComponent>[1]);
|
|
13
|
+
getFormValueFromState(state: FormSubmissionState): LatLongState | undefined;
|
|
14
|
+
getDisplayStringFromFormValue(value: LatLongState | undefined): string;
|
|
15
|
+
getDisplayStringFromState(state: FormSubmissionState): string;
|
|
16
|
+
getContextValueFromFormValue(value: LatLongState | undefined): string | null;
|
|
17
|
+
getContextValueFromState(state: FormSubmissionState): string | null;
|
|
18
|
+
getViewModel(payload: FormPayload, errors?: FormSubmissionError[]): {
|
|
19
|
+
fieldset: {
|
|
20
|
+
attributes?: string | Record<string, string>;
|
|
21
|
+
legend?: import("~/src/server/plugins/engine/components/types.js").Label;
|
|
22
|
+
};
|
|
23
|
+
items: import("~/src/server/plugins/engine/components/types.js").DateInputItem[];
|
|
24
|
+
label: import("~/src/server/plugins/engine/components/types.js").Label;
|
|
25
|
+
type?: string;
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
value: import("~/src/server/plugins/engine/types.js").FormValue;
|
|
29
|
+
hint?: {
|
|
30
|
+
id?: string;
|
|
31
|
+
text: string;
|
|
32
|
+
};
|
|
33
|
+
prefix?: import("~/src/server/plugins/engine/components/types.js").ComponentText;
|
|
34
|
+
suffix?: import("~/src/server/plugins/engine/components/types.js").ComponentText;
|
|
35
|
+
classes?: string;
|
|
36
|
+
condition?: string;
|
|
37
|
+
errors?: FormSubmissionError[];
|
|
38
|
+
errorMessage?: {
|
|
39
|
+
text: string;
|
|
40
|
+
};
|
|
41
|
+
summaryHtml?: string;
|
|
42
|
+
html?: string;
|
|
43
|
+
attributes: {
|
|
44
|
+
autocomplete?: string;
|
|
45
|
+
maxlength?: number;
|
|
46
|
+
multiple?: string;
|
|
47
|
+
accept?: string;
|
|
48
|
+
inputmode?: string;
|
|
49
|
+
};
|
|
50
|
+
content?: import("~/src/server/plugins/engine/components/types.js").Content | import("~/src/server/plugins/engine/components/types.js").Content[] | string;
|
|
51
|
+
maxlength?: number;
|
|
52
|
+
maxwords?: number;
|
|
53
|
+
rows?: number;
|
|
54
|
+
formGroup?: {
|
|
55
|
+
classes?: string;
|
|
56
|
+
attributes?: string | Record<string, string>;
|
|
57
|
+
};
|
|
58
|
+
components?: import("~/src/server/plugins/engine/components/types.js").ComponentViewModel[];
|
|
59
|
+
upload?: {
|
|
60
|
+
count: number;
|
|
61
|
+
summaryList: import("~/src/server/plugins/engine/types.js").SummaryList;
|
|
62
|
+
};
|
|
63
|
+
} | {
|
|
64
|
+
instructionText: string;
|
|
65
|
+
fieldset: {
|
|
66
|
+
attributes?: string | Record<string, string>;
|
|
67
|
+
legend?: import("~/src/server/plugins/engine/components/types.js").Label;
|
|
68
|
+
};
|
|
69
|
+
items: import("~/src/server/plugins/engine/components/types.js").DateInputItem[];
|
|
70
|
+
label: import("~/src/server/plugins/engine/components/types.js").Label;
|
|
71
|
+
type?: string;
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
value: import("~/src/server/plugins/engine/types.js").FormValue;
|
|
75
|
+
hint?: {
|
|
76
|
+
id?: string;
|
|
77
|
+
text: string;
|
|
78
|
+
};
|
|
79
|
+
prefix?: import("~/src/server/plugins/engine/components/types.js").ComponentText;
|
|
80
|
+
suffix?: import("~/src/server/plugins/engine/components/types.js").ComponentText;
|
|
81
|
+
classes?: string;
|
|
82
|
+
condition?: string;
|
|
83
|
+
errors?: FormSubmissionError[];
|
|
84
|
+
errorMessage?: {
|
|
85
|
+
text: string;
|
|
86
|
+
};
|
|
87
|
+
summaryHtml?: string;
|
|
88
|
+
html?: string;
|
|
89
|
+
attributes: {
|
|
90
|
+
autocomplete?: string;
|
|
91
|
+
maxlength?: number;
|
|
92
|
+
multiple?: string;
|
|
93
|
+
accept?: string;
|
|
94
|
+
inputmode?: string;
|
|
95
|
+
};
|
|
96
|
+
content?: import("~/src/server/plugins/engine/components/types.js").Content | import("~/src/server/plugins/engine/components/types.js").Content[] | string;
|
|
97
|
+
maxlength?: number;
|
|
98
|
+
maxwords?: number;
|
|
99
|
+
rows?: number;
|
|
100
|
+
formGroup?: {
|
|
101
|
+
classes?: string;
|
|
102
|
+
attributes?: string | Record<string, string>;
|
|
103
|
+
};
|
|
104
|
+
components?: import("~/src/server/plugins/engine/components/types.js").ComponentViewModel[];
|
|
105
|
+
upload?: {
|
|
106
|
+
count: number;
|
|
107
|
+
summaryList: import("~/src/server/plugins/engine/types.js").SummaryList;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
isState(value?: FormStateValue | FormState): value is LatLongState;
|
|
111
|
+
/**
|
|
112
|
+
* For error preview page that shows all possible errors on a component
|
|
113
|
+
*/
|
|
114
|
+
getAllPossibleErrors(): ErrorMessageTemplateList;
|
|
115
|
+
/**
|
|
116
|
+
* Static version of getAllPossibleErrors that doesn't require a component instance.
|
|
117
|
+
*/
|
|
118
|
+
static getAllPossibleErrors(): ErrorMessageTemplateList;
|
|
119
|
+
static isLatLong(value?: FormStateValue | FormState): value is LatLongState;
|
|
120
|
+
}
|
|
121
|
+
export declare function getValidatorLatLong(component: LatLongField): import("joi").CustomValidator;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { ComponentType } from '@defra/forms-model';
|
|
2
|
+
import { ComponentCollection } from "./ComponentCollection.js";
|
|
3
|
+
import { FormComponent, isFormState } from "./FormComponent.js";
|
|
4
|
+
import { createLocationFieldValidator, getLocationFieldViewModel } from "./LocationFieldHelpers.js";
|
|
5
|
+
import { NumberField } from "./NumberField.js";
|
|
6
|
+
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
7
|
+
import { convertToLanguageMessages } from "../../../utils/type-utils.js";
|
|
8
|
+
export class LatLongField extends FormComponent {
|
|
9
|
+
constructor(def, props) {
|
|
10
|
+
super(def, props);
|
|
11
|
+
const {
|
|
12
|
+
name,
|
|
13
|
+
options,
|
|
14
|
+
schema
|
|
15
|
+
} = def;
|
|
16
|
+
const isRequired = options.required !== false;
|
|
17
|
+
|
|
18
|
+
// Read schema values from def.schema with fallback defaults
|
|
19
|
+
const latitudeMin = schema?.latitude?.min ?? 49;
|
|
20
|
+
const latitudeMax = schema?.latitude?.max ?? 60;
|
|
21
|
+
const longitudeMin = schema?.longitude?.min ?? -9;
|
|
22
|
+
const longitudeMax = schema?.longitude?.max ?? 2;
|
|
23
|
+
const customValidationMessages = convertToLanguageMessages({
|
|
24
|
+
'any.required': messageTemplate.objectMissing,
|
|
25
|
+
'number.base': messageTemplate.objectMissing,
|
|
26
|
+
'number.precision': '{{#label}} must have no more than 7 decimal places',
|
|
27
|
+
'number.unsafe': '{{#label}} must be a valid number'
|
|
28
|
+
});
|
|
29
|
+
const latitudeMessages = convertToLanguageMessages({
|
|
30
|
+
...customValidationMessages,
|
|
31
|
+
'number.base': `Enter a valid latitude for ${this.title} like 51.519450`,
|
|
32
|
+
'number.min': `Latitude for ${this.title} must be between ${latitudeMin} and ${latitudeMax}`,
|
|
33
|
+
'number.max': `Latitude for ${this.title} must be between ${latitudeMin} and ${latitudeMax}`
|
|
34
|
+
});
|
|
35
|
+
const longitudeMessages = convertToLanguageMessages({
|
|
36
|
+
...customValidationMessages,
|
|
37
|
+
'number.base': `Enter a valid longitude for ${this.title} like -0.127758`,
|
|
38
|
+
'number.min': `Longitude for ${this.title} must be between ${longitudeMin} and ${longitudeMax}`,
|
|
39
|
+
'number.max': `Longitude for ${this.title} must be between ${longitudeMin} and ${longitudeMax}`
|
|
40
|
+
});
|
|
41
|
+
this.collection = new ComponentCollection([{
|
|
42
|
+
type: ComponentType.NumberField,
|
|
43
|
+
name: `${name}__latitude`,
|
|
44
|
+
title: 'Latitude',
|
|
45
|
+
schema: {
|
|
46
|
+
min: latitudeMin,
|
|
47
|
+
max: latitudeMax,
|
|
48
|
+
precision: 7
|
|
49
|
+
},
|
|
50
|
+
options: {
|
|
51
|
+
required: isRequired,
|
|
52
|
+
optionalText: true,
|
|
53
|
+
classes: 'govuk-input--width-10',
|
|
54
|
+
suffix: '°',
|
|
55
|
+
customValidationMessages: latitudeMessages
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
type: ComponentType.NumberField,
|
|
59
|
+
name: `${name}__longitude`,
|
|
60
|
+
title: 'Longitude',
|
|
61
|
+
schema: {
|
|
62
|
+
min: longitudeMin,
|
|
63
|
+
max: longitudeMax,
|
|
64
|
+
precision: 7
|
|
65
|
+
},
|
|
66
|
+
options: {
|
|
67
|
+
required: isRequired,
|
|
68
|
+
optionalText: true,
|
|
69
|
+
classes: 'govuk-input--width-10',
|
|
70
|
+
suffix: '°',
|
|
71
|
+
customValidationMessages: longitudeMessages
|
|
72
|
+
}
|
|
73
|
+
}], {
|
|
74
|
+
...props,
|
|
75
|
+
parent: this
|
|
76
|
+
}, {
|
|
77
|
+
custom: getValidatorLatLong(this),
|
|
78
|
+
peers: [`${name}__latitude`, `${name}__longitude`]
|
|
79
|
+
});
|
|
80
|
+
this.options = options;
|
|
81
|
+
this.formSchema = this.collection.formSchema;
|
|
82
|
+
this.stateSchema = this.collection.stateSchema;
|
|
83
|
+
}
|
|
84
|
+
getFormValueFromState(state) {
|
|
85
|
+
const value = super.getFormValueFromState(state);
|
|
86
|
+
return LatLongField.isLatLong(value) ? value : undefined;
|
|
87
|
+
}
|
|
88
|
+
getDisplayStringFromFormValue(value) {
|
|
89
|
+
if (!value) {
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// CYA page format: <<latvalue, langvalue>>
|
|
94
|
+
return `${value.latitude}, ${value.longitude}`;
|
|
95
|
+
}
|
|
96
|
+
getDisplayStringFromState(state) {
|
|
97
|
+
const value = this.getFormValueFromState(state);
|
|
98
|
+
return this.getDisplayStringFromFormValue(value);
|
|
99
|
+
}
|
|
100
|
+
getContextValueFromFormValue(value) {
|
|
101
|
+
if (!value) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Output format: Lat: <<entry>>\nLong: <<entry>>
|
|
106
|
+
return `Lat: ${value.latitude}\nLong: ${value.longitude}`;
|
|
107
|
+
}
|
|
108
|
+
getContextValueFromState(state) {
|
|
109
|
+
const value = this.getFormValueFromState(state);
|
|
110
|
+
return this.getContextValueFromFormValue(value);
|
|
111
|
+
}
|
|
112
|
+
getViewModel(payload, errors) {
|
|
113
|
+
const viewModel = super.getViewModel(payload, errors);
|
|
114
|
+
return getLocationFieldViewModel(this, viewModel, payload, errors);
|
|
115
|
+
}
|
|
116
|
+
isState(value) {
|
|
117
|
+
return LatLongField.isLatLong(value);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* For error preview page that shows all possible errors on a component
|
|
122
|
+
*/
|
|
123
|
+
getAllPossibleErrors() {
|
|
124
|
+
return LatLongField.getAllPossibleErrors();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Static version of getAllPossibleErrors that doesn't require a component instance.
|
|
129
|
+
*/
|
|
130
|
+
static getAllPossibleErrors() {
|
|
131
|
+
return {
|
|
132
|
+
baseErrors: [{
|
|
133
|
+
type: 'required',
|
|
134
|
+
template: messageTemplate.required
|
|
135
|
+
}, {
|
|
136
|
+
type: 'latitudeFormat',
|
|
137
|
+
template: 'Enter a valid latitude for [short description] like 51.519450'
|
|
138
|
+
}, {
|
|
139
|
+
type: 'longitudeFormat',
|
|
140
|
+
template: 'Enter a valid longitude for [short description] like -0.127758'
|
|
141
|
+
}],
|
|
142
|
+
advancedSettingsErrors: [{
|
|
143
|
+
type: 'latitudeMin',
|
|
144
|
+
template: 'Latitude for [short description] must be between 49 and 60'
|
|
145
|
+
}, {
|
|
146
|
+
type: 'latitudeMax',
|
|
147
|
+
template: 'Latitude for [short description] must be between 49 and 60'
|
|
148
|
+
}, {
|
|
149
|
+
type: 'longitudeMin',
|
|
150
|
+
template: 'Longitude for [short description] must be between -9 and 2'
|
|
151
|
+
}, {
|
|
152
|
+
type: 'longitudeMax',
|
|
153
|
+
template: 'Longitude for [short description] must be between -9 and 2'
|
|
154
|
+
}]
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
static isLatLong(value) {
|
|
158
|
+
return isFormState(value) && NumberField.isNumber(value.latitude) && NumberField.isNumber(value.longitude);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export function getValidatorLatLong(component) {
|
|
162
|
+
return createLocationFieldValidator(component);
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=LatLongField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LatLongField.js","names":["ComponentType","ComponentCollection","FormComponent","isFormState","createLocationFieldValidator","getLocationFieldViewModel","NumberField","messageTemplate","convertToLanguageMessages","LatLongField","constructor","def","props","name","options","schema","isRequired","required","latitudeMin","latitude","min","latitudeMax","max","longitudeMin","longitude","longitudeMax","customValidationMessages","objectMissing","latitudeMessages","title","longitudeMessages","collection","type","precision","optionalText","classes","suffix","parent","custom","getValidatorLatLong","peers","formSchema","stateSchema","getFormValueFromState","state","value","isLatLong","undefined","getDisplayStringFromFormValue","getDisplayStringFromState","getContextValueFromFormValue","getContextValueFromState","getViewModel","payload","errors","viewModel","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isNumber","component"],"sources":["../../../../../src/server/plugins/engine/components/LatLongField.ts"],"sourcesContent":["import { ComponentType, type LatLongFieldComponent } from '@defra/forms-model'\nimport { type LanguageMessages, type ObjectSchema } from 'joi'\n\nimport { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'\nimport {\n FormComponent,\n isFormState\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport {\n createLocationFieldValidator,\n getLocationFieldViewModel\n} from '~/src/server/plugins/engine/components/LocationFieldHelpers.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport { type LatLongState } from '~/src/server/plugins/engine/components/types.js'\nimport { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'\nimport {\n type ErrorMessageTemplateList,\n type FormPayload,\n type FormState,\n type FormStateValue,\n type FormSubmissionError,\n type FormSubmissionState\n} from '~/src/server/plugins/engine/types.js'\nimport { convertToLanguageMessages } from '~/src/server/utils/type-utils.js'\n\nexport class LatLongField extends FormComponent {\n declare options: LatLongFieldComponent['options']\n declare formSchema: ObjectSchema<FormPayload>\n declare stateSchema: ObjectSchema<FormState>\n declare collection: ComponentCollection\n\n constructor(\n def: LatLongFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { name, options, schema } = def\n\n const isRequired = options.required !== false\n\n // Read schema values from def.schema with fallback defaults\n const latitudeMin = schema?.latitude?.min ?? 49\n const latitudeMax = schema?.latitude?.max ?? 60\n const longitudeMin = schema?.longitude?.min ?? -9\n const longitudeMax = schema?.longitude?.max ?? 2\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n 'any.required': messageTemplate.objectMissing,\n 'number.base': messageTemplate.objectMissing,\n 'number.precision':\n '{{#label}} must have no more than 7 decimal places',\n 'number.unsafe': '{{#label}} must be a valid number'\n })\n\n const latitudeMessages: LanguageMessages = convertToLanguageMessages({\n ...customValidationMessages,\n 'number.base': `Enter a valid latitude for ${this.title} like 51.519450`,\n 'number.min': `Latitude for ${this.title} must be between ${latitudeMin} and ${latitudeMax}`,\n 'number.max': `Latitude for ${this.title} must be between ${latitudeMin} and ${latitudeMax}`\n })\n\n const longitudeMessages: LanguageMessages = convertToLanguageMessages({\n ...customValidationMessages,\n 'number.base': `Enter a valid longitude for ${this.title} like -0.127758`,\n 'number.min': `Longitude for ${this.title} must be between ${longitudeMin} and ${longitudeMax}`,\n 'number.max': `Longitude for ${this.title} must be between ${longitudeMin} and ${longitudeMax}`\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__latitude`,\n title: 'Latitude',\n schema: { min: latitudeMin, max: latitudeMax, precision: 7 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-10',\n suffix: '°',\n customValidationMessages: latitudeMessages\n }\n },\n {\n type: ComponentType.NumberField,\n name: `${name}__longitude`,\n title: 'Longitude',\n schema: { min: longitudeMin, max: longitudeMax, precision: 7 },\n options: {\n required: isRequired,\n optionalText: true,\n classes: 'govuk-input--width-10',\n suffix: '°',\n customValidationMessages: longitudeMessages\n }\n }\n ],\n { ...props, parent: this },\n {\n custom: getValidatorLatLong(this),\n peers: [`${name}__latitude`, `${name}__longitude`]\n }\n )\n\n this.options = options\n this.formSchema = this.collection.formSchema\n this.stateSchema = this.collection.stateSchema\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const value = super.getFormValueFromState(state)\n return LatLongField.isLatLong(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(value: LatLongState | undefined): string {\n if (!value) {\n return ''\n }\n\n // CYA page format: <<latvalue, langvalue>>\n return `${value.latitude}, ${value.longitude}`\n }\n\n getDisplayStringFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n return this.getDisplayStringFromFormValue(value)\n }\n\n getContextValueFromFormValue(value: LatLongState | undefined): string | null {\n if (!value) {\n return null\n }\n\n // Output format: Lat: <<entry>>\\nLong: <<entry>>\n return `Lat: ${value.latitude}\\nLong: ${value.longitude}`\n }\n\n getContextValueFromState(state: FormSubmissionState) {\n const value = this.getFormValueFromState(state)\n\n return this.getContextValueFromFormValue(value)\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const viewModel = super.getViewModel(payload, errors)\n return getLocationFieldViewModel(this, viewModel, payload, errors)\n }\n\n isState(value?: FormStateValue | FormState) {\n return LatLongField.isLatLong(value)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return LatLongField.getAllPossibleErrors()\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n {\n type: 'latitudeFormat',\n template:\n 'Enter a valid latitude for [short description] like 51.519450'\n },\n {\n type: 'longitudeFormat',\n template:\n 'Enter a valid longitude for [short description] like -0.127758'\n }\n ],\n advancedSettingsErrors: [\n {\n type: 'latitudeMin',\n template: 'Latitude for [short description] must be between 49 and 60'\n },\n {\n type: 'latitudeMax',\n template: 'Latitude for [short description] must be between 49 and 60'\n },\n {\n type: 'longitudeMin',\n template: 'Longitude for [short description] must be between -9 and 2'\n },\n {\n type: 'longitudeMax',\n template: 'Longitude for [short description] must be between -9 and 2'\n }\n ]\n }\n }\n\n static isLatLong(value?: FormStateValue | FormState): value is LatLongState {\n return (\n isFormState(value) &&\n NumberField.isNumber(value.latitude) &&\n NumberField.isNumber(value.longitude)\n )\n }\n}\n\nexport function getValidatorLatLong(component: LatLongField) {\n return createLocationFieldValidator(component)\n}\n"],"mappings":"AAAA,SAASA,aAAa,QAAoC,oBAAoB;AAG9E,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW;AAEb,SACEC,4BAA4B,EAC5BC,yBAAyB;AAE3B,SAASC,WAAW;AAEpB,SAASC,eAAe;AASxB,SAASC,yBAAyB;AAElC,OAAO,MAAMC,YAAY,SAASP,aAAa,CAAC;EAM9CQ,WAAWA,CACTC,GAA0B,EAC1BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,IAAI;MAAEC,OAAO;MAAEC;IAAO,CAAC,GAAGJ,GAAG;IAErC,MAAMK,UAAU,GAAGF,OAAO,CAACG,QAAQ,KAAK,KAAK;;IAE7C;IACA,MAAMC,WAAW,GAAGH,MAAM,EAAEI,QAAQ,EAAEC,GAAG,IAAI,EAAE;IAC/C,MAAMC,WAAW,GAAGN,MAAM,EAAEI,QAAQ,EAAEG,GAAG,IAAI,EAAE;IAC/C,MAAMC,YAAY,GAAGR,MAAM,EAAES,SAAS,EAAEJ,GAAG,IAAI,CAAC,CAAC;IACjD,MAAMK,YAAY,GAAGV,MAAM,EAAES,SAAS,EAAEF,GAAG,IAAI,CAAC;IAEhD,MAAMI,wBAA0C,GAC9ClB,yBAAyB,CAAC;MACxB,cAAc,EAAED,eAAe,CAACoB,aAAa;MAC7C,aAAa,EAAEpB,eAAe,CAACoB,aAAa;MAC5C,kBAAkB,EAChB,oDAAoD;MACtD,eAAe,EAA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C,WAAW,CAAC0C,KAAK,CAAC,IAClBvC,WAAW,CAACuD,QAAQ,CAAChB,KAAK,CAAC1B,QAAQ,CAAC,IACpCb,WAAW,CAACuD,QAAQ,CAAChB,KAAK,CAACrB,SAAS,CAAC;EAEzC;AACF;AAEA,OAAO,SAASe,mBAAmBA,CAACuB,SAAuB,EAAE;EAC3D,OAAO1D,4BAA4B,CAAC0D,SAAS,CAAC;AAChD","ignoreList":[]}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { type FormComponentsDef } from '@defra/forms-model';
|
|
2
|
+
import joi, { type LanguageMessages, type StringSchema } from 'joi';
|
|
3
|
+
import { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js';
|
|
4
|
+
import { type ErrorMessageTemplateList, type FormPayload, type FormState, type FormStateValue, type FormSubmissionError, type FormSubmissionState } from '~/src/server/plugins/engine/types.js';
|
|
5
|
+
interface LocationFieldOptions {
|
|
6
|
+
instructionText?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
customValidationMessage?: string;
|
|
9
|
+
customValidationMessages?: LanguageMessages;
|
|
10
|
+
classes?: string;
|
|
11
|
+
}
|
|
12
|
+
interface ValidationConfig {
|
|
13
|
+
pattern: RegExp;
|
|
14
|
+
patternErrorMessage: string;
|
|
15
|
+
customValidation?: (value: string, helpers: joi.CustomHelpers) => string | joi.ErrorReport;
|
|
16
|
+
additionalMessages?: LanguageMessages;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Abstract base class for location-based field components
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class LocationFieldBase extends FormComponent {
|
|
22
|
+
options: LocationFieldOptions;
|
|
23
|
+
formSchema: StringSchema;
|
|
24
|
+
stateSchema: StringSchema;
|
|
25
|
+
instructionText?: string;
|
|
26
|
+
protected abstract getValidationConfig(): ValidationConfig;
|
|
27
|
+
protected abstract getErrorTemplates(): {
|
|
28
|
+
type: string;
|
|
29
|
+
template: string;
|
|
30
|
+
}[];
|
|
31
|
+
constructor(def: FormComponentsDef, props: ConstructorParameters<typeof FormComponent>[1]);
|
|
32
|
+
getFormValueFromState(state: FormSubmissionState): string | undefined;
|
|
33
|
+
getFormValue(value?: FormStateValue | FormState): string | undefined;
|
|
34
|
+
isValue(value?: FormStateValue | FormState): value is string;
|
|
35
|
+
getViewModel(payload: FormPayload, errors?: FormSubmissionError[]): {
|
|
36
|
+
label: {
|
|
37
|
+
text: string;
|
|
38
|
+
};
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
value: import("~/src/server/plugins/engine/types.js").FormValue;
|
|
42
|
+
type?: string;
|
|
43
|
+
hint?: {
|
|
44
|
+
id?: string;
|
|
45
|
+
text: string;
|
|
46
|
+
};
|
|
47
|
+
prefix?: import("./types.js").ComponentText;
|
|
48
|
+
suffix?: import("./types.js").ComponentText;
|
|
49
|
+
classes?: string;
|
|
50
|
+
condition?: string;
|
|
51
|
+
errors?: FormSubmissionError[];
|
|
52
|
+
errorMessage?: {
|
|
53
|
+
text: string;
|
|
54
|
+
};
|
|
55
|
+
summaryHtml?: string;
|
|
56
|
+
html?: string;
|
|
57
|
+
attributes: {
|
|
58
|
+
autocomplete?: string;
|
|
59
|
+
maxlength?: number;
|
|
60
|
+
multiple?: string;
|
|
61
|
+
accept?: string;
|
|
62
|
+
inputmode?: string;
|
|
63
|
+
};
|
|
64
|
+
content?: import("./types.js").Content | import("./types.js").Content[] | string;
|
|
65
|
+
maxlength?: number;
|
|
66
|
+
maxwords?: number;
|
|
67
|
+
rows?: number;
|
|
68
|
+
items?: import("./types.js").ListItem[] | import("./types.js").DateInputItem[];
|
|
69
|
+
fieldset?: {
|
|
70
|
+
attributes?: string | Record<string, string>;
|
|
71
|
+
legend?: import("./types.js").Label;
|
|
72
|
+
};
|
|
73
|
+
formGroup?: {
|
|
74
|
+
classes?: string;
|
|
75
|
+
attributes?: string | Record<string, string>;
|
|
76
|
+
};
|
|
77
|
+
components?: import("./types.js").ComponentViewModel[];
|
|
78
|
+
upload?: {
|
|
79
|
+
count: number;
|
|
80
|
+
summaryList: import("~/src/server/plugins/engine/types.js").SummaryList;
|
|
81
|
+
};
|
|
82
|
+
} | {
|
|
83
|
+
instructionText: string;
|
|
84
|
+
label: {
|
|
85
|
+
text: string;
|
|
86
|
+
};
|
|
87
|
+
id: string;
|
|
88
|
+
name: string;
|
|
89
|
+
value: import("~/src/server/plugins/engine/types.js").FormValue;
|
|
90
|
+
type?: string;
|
|
91
|
+
hint?: {
|
|
92
|
+
id?: string;
|
|
93
|
+
text: string;
|
|
94
|
+
};
|
|
95
|
+
prefix?: import("./types.js").ComponentText;
|
|
96
|
+
suffix?: import("./types.js").ComponentText;
|
|
97
|
+
classes?: string;
|
|
98
|
+
condition?: string;
|
|
99
|
+
errors?: FormSubmissionError[];
|
|
100
|
+
errorMessage?: {
|
|
101
|
+
text: string;
|
|
102
|
+
};
|
|
103
|
+
summaryHtml?: string;
|
|
104
|
+
html?: string;
|
|
105
|
+
attributes: {
|
|
106
|
+
autocomplete?: string;
|
|
107
|
+
maxlength?: number;
|
|
108
|
+
multiple?: string;
|
|
109
|
+
accept?: string;
|
|
110
|
+
inputmode?: string;
|
|
111
|
+
};
|
|
112
|
+
content?: import("./types.js").Content | import("./types.js").Content[] | string;
|
|
113
|
+
maxlength?: number;
|
|
114
|
+
maxwords?: number;
|
|
115
|
+
rows?: number;
|
|
116
|
+
items?: import("./types.js").ListItem[] | import("./types.js").DateInputItem[];
|
|
117
|
+
fieldset?: {
|
|
118
|
+
attributes?: string | Record<string, string>;
|
|
119
|
+
legend?: import("./types.js").Label;
|
|
120
|
+
};
|
|
121
|
+
formGroup?: {
|
|
122
|
+
classes?: string;
|
|
123
|
+
attributes?: string | Record<string, string>;
|
|
124
|
+
};
|
|
125
|
+
components?: import("./types.js").ComponentViewModel[];
|
|
126
|
+
upload?: {
|
|
127
|
+
count: number;
|
|
128
|
+
summaryList: import("~/src/server/plugins/engine/types.js").SummaryList;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
getAllPossibleErrors(): ErrorMessageTemplateList;
|
|
132
|
+
static isText(value?: FormStateValue | FormState): value is string;
|
|
133
|
+
}
|
|
134
|
+
export {};
|