@defra/forms-engine-plugin 4.0.5 → 4.0.7
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 +2 -2
- 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 -6
- package/.server/client/stylesheets/shared.scss +8 -0
- package/.server/server/forms/register-as-a-unicorn-breeder.yaml +28 -0
- package/.server/server/plugins/engine/components/ComponentBase.d.ts +1 -1
- package/.server/server/plugins/engine/components/ComponentBase.js.map +1 -1
- 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 +21 -29
- package/.server/server/plugins/engine/components/helpers/components.js.map +1 -1
- package/.server/server/plugins/engine/components/index.d.ts +4 -0
- package/.server/server/plugins/engine/components/index.js +4 -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/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/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/package.json +3 -3
- package/src/client/stylesheets/_location-input.scss +60 -0
- package/src/client/stylesheets/application.scss +1 -6
- package/src/client/stylesheets/shared.scss +8 -0
- package/src/server/forms/register-as-a-unicorn-breeder.yaml +28 -0
- package/src/server/plugins/engine/components/ComponentBase.ts +1 -1
- 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 +39 -47
- package/src/server/plugins/engine/components/helpers/helpers.test.ts +71 -1
- package/src/server/plugins/engine/components/index.ts +4 -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/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/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/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
|
@@ -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,EAAE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AC,CACF;MACDC,sBAAsB,EAAE,CACtB;QACE5B,IAAI,EAAE,aAAa;QACnB2B,QAAQ,EAAE;MACZ,CAAC,EACD;QACE3B,IAAI,EAAE,aAAa;QACnB2B,QAAQ,EAAE;MACZ,CAAC,EACD;QACE3B,IAAI,EAAE,cAAc;QACpB2B,QAAQ,EAAE;MACZ,CAAC,EACD;QACE3B,IAAI,EAAE,cAAc;QACpB2B,QAAQ,EAAE;MACZ,CAAC;IAEL,CAAC;EACH;EAEA,OAAOb,SAASA,CAACD,KAAkC,EAAyB;IAC1E,OACE1C,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 {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
import { FormComponent, isFormValue } from "./FormComponent.js";
|
|
3
|
+
import { addClassOptionIfNone } from "./helpers/index.js";
|
|
4
|
+
import { markdown } from "./markdownParser.js";
|
|
5
|
+
import { messageTemplate } from "../pageControllers/validationOptions.js";
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class for location-based field components
|
|
8
|
+
*/
|
|
9
|
+
export class LocationFieldBase extends FormComponent {
|
|
10
|
+
instructionText;
|
|
11
|
+
constructor(def, props) {
|
|
12
|
+
super(def, props);
|
|
13
|
+
const {
|
|
14
|
+
options
|
|
15
|
+
} = def;
|
|
16
|
+
const locationOptions = options;
|
|
17
|
+
this.instructionText = locationOptions.instructionText;
|
|
18
|
+
addClassOptionIfNone(locationOptions, 'govuk-input--width-10');
|
|
19
|
+
const config = this.getValidationConfig();
|
|
20
|
+
let formSchema = joi.string().trim().label(this.label).required().pattern(config.pattern).messages({
|
|
21
|
+
'string.pattern.base': config.patternErrorMessage,
|
|
22
|
+
...config.additionalMessages
|
|
23
|
+
});
|
|
24
|
+
if (config.customValidation) {
|
|
25
|
+
formSchema = formSchema.custom(config.customValidation);
|
|
26
|
+
}
|
|
27
|
+
if (locationOptions.required === false) {
|
|
28
|
+
formSchema = formSchema.allow('');
|
|
29
|
+
}
|
|
30
|
+
if (locationOptions.customValidationMessage) {
|
|
31
|
+
const message = locationOptions.customValidationMessage;
|
|
32
|
+
const messageKeys = ['any.required', 'string.empty', 'string.pattern.base'];
|
|
33
|
+
if (config.additionalMessages) {
|
|
34
|
+
messageKeys.push(...Object.keys(config.additionalMessages));
|
|
35
|
+
}
|
|
36
|
+
const messages = messageKeys.reduce((acc, key) => {
|
|
37
|
+
acc[key] = message;
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
formSchema = formSchema.messages(messages);
|
|
41
|
+
} else if (locationOptions.customValidationMessages) {
|
|
42
|
+
formSchema = formSchema.messages(locationOptions.customValidationMessages);
|
|
43
|
+
}
|
|
44
|
+
this.formSchema = formSchema.default('');
|
|
45
|
+
this.stateSchema = formSchema.default(null).allow(null);
|
|
46
|
+
this.options = locationOptions;
|
|
47
|
+
}
|
|
48
|
+
getFormValueFromState(state) {
|
|
49
|
+
const {
|
|
50
|
+
name
|
|
51
|
+
} = this;
|
|
52
|
+
return this.getFormValue(state[name]);
|
|
53
|
+
}
|
|
54
|
+
getFormValue(value) {
|
|
55
|
+
return this.isValue(value) ? value : undefined;
|
|
56
|
+
}
|
|
57
|
+
isValue(value) {
|
|
58
|
+
return LocationFieldBase.isText(value);
|
|
59
|
+
}
|
|
60
|
+
getViewModel(payload, errors) {
|
|
61
|
+
const viewModel = super.getViewModel(payload, errors);
|
|
62
|
+
if (this.instructionText) {
|
|
63
|
+
return {
|
|
64
|
+
...viewModel,
|
|
65
|
+
instructionText: markdown.parse(this.instructionText, {
|
|
66
|
+
async: false
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return viewModel;
|
|
71
|
+
}
|
|
72
|
+
getAllPossibleErrors() {
|
|
73
|
+
return {
|
|
74
|
+
baseErrors: [{
|
|
75
|
+
type: 'required',
|
|
76
|
+
template: messageTemplate.required
|
|
77
|
+
}, ...this.getErrorTemplates()],
|
|
78
|
+
advancedSettingsErrors: []
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
static isText(value) {
|
|
82
|
+
return isFormValue(value) && typeof value === 'string';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=LocationFieldBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocationFieldBase.js","names":["joi","FormComponent","isFormValue","addClassOptionIfNone","markdown","messageTemplate","LocationFieldBase","instructionText","constructor","def","props","options","locationOptions","config","getValidationConfig","formSchema","string","trim","label","required","pattern","messages","patternErrorMessage","additionalMessages","customValidation","custom","allow","customValidationMessage","message","messageKeys","push","Object","keys","reduce","acc","key","customValidationMessages","default","stateSchema","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","isText","getViewModel","payload","errors","viewModel","parse","async","getAllPossibleErrors","baseErrors","type","template","getErrorTemplates","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/LocationFieldBase.ts"],"sourcesContent":["import { type FormComponentsDef } from '@defra/forms-model'\nimport joi, { type LanguageMessages, type StringSchema } from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { addClassOptionIfNone } from '~/src/server/plugins/engine/components/helpers/index.js'\nimport { markdown } from '~/src/server/plugins/engine/components/markdownParser.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'\n\ninterface LocationFieldOptions {\n instructionText?: string\n required?: boolean\n customValidationMessage?: string\n customValidationMessages?: LanguageMessages\n classes?: string\n}\n\ninterface ValidationConfig {\n pattern: RegExp\n patternErrorMessage: string\n customValidation?: (\n value: string,\n helpers: joi.CustomHelpers\n ) => string | joi.ErrorReport\n additionalMessages?: LanguageMessages\n}\n\n/**\n * Abstract base class for location-based field components\n */\nexport abstract class LocationFieldBase extends FormComponent {\n declare options: LocationFieldOptions\n declare formSchema: StringSchema\n declare stateSchema: StringSchema\n instructionText?: string\n\n protected abstract getValidationConfig(): ValidationConfig\n protected abstract getErrorTemplates(): {\n type: string\n template: string\n }[]\n\n constructor(\n def: FormComponentsDef,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options } = def\n const locationOptions = options as LocationFieldOptions\n this.instructionText = locationOptions.instructionText\n\n addClassOptionIfNone(locationOptions, 'govuk-input--width-10')\n\n const config = this.getValidationConfig()\n\n let formSchema = joi\n .string()\n .trim()\n .label(this.label)\n .required()\n .pattern(config.pattern)\n .messages({\n 'string.pattern.base': config.patternErrorMessage,\n ...config.additionalMessages\n })\n\n if (config.customValidation) {\n formSchema = formSchema.custom(config.customValidation)\n }\n\n if (locationOptions.required === false) {\n formSchema = formSchema.allow('')\n }\n\n if (locationOptions.customValidationMessage) {\n const message = locationOptions.customValidationMessage\n const messageKeys = [\n 'any.required',\n 'string.empty',\n 'string.pattern.base'\n ]\n\n if (config.additionalMessages) {\n messageKeys.push(...Object.keys(config.additionalMessages))\n }\n\n const messages = messageKeys.reduce<LanguageMessages>((acc, key) => {\n acc[key] = message\n return acc\n }, {})\n\n formSchema = formSchema.messages(messages)\n } else if (locationOptions.customValidationMessages) {\n formSchema = formSchema.messages(locationOptions.customValidationMessages)\n }\n\n this.formSchema = formSchema.default('')\n this.stateSchema = formSchema.default(null).allow(null)\n this.options = locationOptions\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return this.getFormValue(state[name])\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n isValue(value?: FormStateValue | FormState): value is string {\n return LocationFieldBase.isText(value)\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const viewModel = super.getViewModel(payload, errors)\n\n if (this.instructionText) {\n return {\n ...viewModel,\n instructionText: markdown.parse(this.instructionText, { async: false })\n }\n }\n\n return viewModel\n }\n\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return {\n baseErrors: [\n { type: 'required', template: messageTemplate.required },\n ...this.getErrorTemplates()\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isText(value?: FormStateValue | FormState): value is string {\n return isFormValue(value) && typeof value === 'string'\n }\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAAoD,KAAK;AAEnE,SACEC,aAAa,EACbC,WAAW;AAEb,SAASC,oBAAoB;AAC7B,SAASC,QAAQ;AACjB,SAASC,eAAe;AA4BxB;AACA;AACA;AACA,OAAO,MAAeC,iBAAiB,SAASL,aAAa,CAAC;EAI5DM,eAAe;EAQfC,WAAWA,CACTC,GAAsB,EACtBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC;IAAQ,CAAC,GAAGF,GAAG;IACvB,MAAMG,eAAe,GAAGD,OAA+B;IACvD,IAAI,CAACJ,eAAe,GAAGK,eAAe,CAACL,eAAe;IAEtDJ,oBAAoB,CAACS,eAAe,EAAE,uBAAuB,CAAC;IAE9D,MAAMC,MAAM,GAAG,IAAI,CAACC,mBAAmB,CAAC,CAAC;IAEzC,IAAIC,UAAU,GAAGf,GAAG,CACjBgB,MAAM,CAAC,CAAC,CACRC,IAAI,CAAC,CAAC,CACNC,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CACjBC,QAAQ,CAAC,CAAC,CACVC,OAAO,CAACP,MAAM,CAACO,OAAO,CAAC,CACvBC,QAAQ,CAAC;MACR,qBAAqB,EAAER,MAAM,CAACS,mBAAmB;MACjD,GAAGT,MAAM,CAACU;IACZ,CAAC,CAAC;IAEJ,IAAIV,MAAM,CAACW,gBAAgB,EAAE;MAC3BT,UAAU,GAAGA,UAAU,CAACU,MAAM,CAACZ,MAAM,CAACW,gBAAgB,CAAC;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ACD,KAAK,CAAC,GAAGA,KAAK,GAAGE,SAAS;EAChD;EAEAD,OAAOA,CAACD,KAAkC,EAAmB;IAC3D,OAAOrC,iBAAiB,CAACwC,MAAM,CAACH,KAAK,CAAC;EACxC;EAEAI,YAAYA,CAACC,OAAoB,EAAEC,MAA8B,EAAE;IACjE,MAAMC,SAAS,GAAG,KAAK,CAACH,YAAY,CAACC,OAAO,EAAEC,MAAM,CAAC;IAErD,IAAI,IAAI,CAAC1C,eAAe,EAAE;MACxB,OAAO;QACL,GAAG2C,SAAS;QACZ3C,eAAe,EAAEH,QAAQ,CAAC+C,KAAK,CAAC,IAAI,CAAC5C,eAAe,EAAE;UAAE6C,KAAK,EAAE;QAAM,CAAC;MACxE,CAAC;IACH;IAEA,OAAOF,SAAS;EAClB;EAEAG,oBAAoBA,CAAA,EAA6B;IAC/C,OAAO;MACLC,UAAU,EAAE,CACV;QAAEC,IAAI,EAAE,UAAU;QAAEC,QAAQ,EAAEnD,eAAe,CAACc;MAAS,CAAC,EACxD,GAAG,IAAI,CAACsC,iBAAiB,CAAC,CAAC,CAC5B;MACDC,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOZ,MAAMA,CAACH,KAAkC,EAAmB;IACjE,OAAOzC,WAAW,CAACyC,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,QAAQ;EACxD;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type CustomValidator } from 'joi';
|
|
2
|
+
import { type EastingNorthingField } from '~/src/server/plugins/engine/components/EastingNorthingField.js';
|
|
3
|
+
import { type LatLongField } from '~/src/server/plugins/engine/components/LatLongField.js';
|
|
4
|
+
import { type DateInputItem, type Label, type ViewModel } from '~/src/server/plugins/engine/components/types.js';
|
|
5
|
+
import { type FormPayload, type FormSubmissionError, type FormValue } from '~/src/server/plugins/engine/types.js';
|
|
6
|
+
export type LocationField = InstanceType<typeof EastingNorthingField> | InstanceType<typeof LatLongField>;
|
|
7
|
+
export declare function getLocationFieldViewModel(component: LocationField, viewModel: ViewModel & {
|
|
8
|
+
label: Label;
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
value: FormValue;
|
|
12
|
+
}, payload: FormPayload, errors?: FormSubmissionError[]): {
|
|
13
|
+
fieldset: {
|
|
14
|
+
attributes?: string | Record<string, string>;
|
|
15
|
+
legend?: Label;
|
|
16
|
+
};
|
|
17
|
+
items: DateInputItem[];
|
|
18
|
+
label: Label;
|
|
19
|
+
type?: string;
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
value: FormValue;
|
|
23
|
+
hint?: {
|
|
24
|
+
id?: string;
|
|
25
|
+
text: string;
|
|
26
|
+
};
|
|
27
|
+
prefix?: import("~/src/server/plugins/engine/components/types.js").ComponentText;
|
|
28
|
+
suffix?: import("~/src/server/plugins/engine/components/types.js").ComponentText;
|
|
29
|
+
classes?: string;
|
|
30
|
+
condition?: string;
|
|
31
|
+
errors?: FormSubmissionError[];
|
|
32
|
+
errorMessage?: {
|
|
33
|
+
text: string;
|
|
34
|
+
};
|
|
35
|
+
summaryHtml?: string;
|
|
36
|
+
html?: string;
|
|
37
|
+
attributes: {
|
|
38
|
+
autocomplete?: string;
|
|
39
|
+
maxlength?: number;
|
|
40
|
+
multiple?: string;
|
|
41
|
+
accept?: string;
|
|
42
|
+
inputmode?: string;
|
|
43
|
+
};
|
|
44
|
+
content?: import("~/src/server/plugins/engine/components/types.js").Content | import("~/src/server/plugins/engine/components/types.js").Content[] | string;
|
|
45
|
+
maxlength?: number;
|
|
46
|
+
maxwords?: number;
|
|
47
|
+
rows?: number;
|
|
48
|
+
formGroup?: {
|
|
49
|
+
classes?: string;
|
|
50
|
+
attributes?: string | Record<string, string>;
|
|
51
|
+
};
|
|
52
|
+
components?: import("~/src/server/plugins/engine/components/types.js").ComponentViewModel[];
|
|
53
|
+
upload?: {
|
|
54
|
+
count: number;
|
|
55
|
+
summaryList: import("~/src/server/plugins/engine/types.js").SummaryList;
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
instructionText: string;
|
|
59
|
+
fieldset: {
|
|
60
|
+
attributes?: string | Record<string, string>;
|
|
61
|
+
legend?: Label;
|
|
62
|
+
};
|
|
63
|
+
items: DateInputItem[];
|
|
64
|
+
label: Label;
|
|
65
|
+
type?: string;
|
|
66
|
+
id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
value: FormValue;
|
|
69
|
+
hint?: {
|
|
70
|
+
id?: string;
|
|
71
|
+
text: string;
|
|
72
|
+
};
|
|
73
|
+
prefix?: import("~/src/server/plugins/engine/components/types.js").ComponentText;
|
|
74
|
+
suffix?: import("~/src/server/plugins/engine/components/types.js").ComponentText;
|
|
75
|
+
classes?: string;
|
|
76
|
+
condition?: string;
|
|
77
|
+
errors?: FormSubmissionError[];
|
|
78
|
+
errorMessage?: {
|
|
79
|
+
text: string;
|
|
80
|
+
};
|
|
81
|
+
summaryHtml?: string;
|
|
82
|
+
html?: string;
|
|
83
|
+
attributes: {
|
|
84
|
+
autocomplete?: string;
|
|
85
|
+
maxlength?: number;
|
|
86
|
+
multiple?: string;
|
|
87
|
+
accept?: string;
|
|
88
|
+
inputmode?: string;
|
|
89
|
+
};
|
|
90
|
+
content?: import("~/src/server/plugins/engine/components/types.js").Content | import("~/src/server/plugins/engine/components/types.js").Content[] | string;
|
|
91
|
+
maxlength?: number;
|
|
92
|
+
maxwords?: number;
|
|
93
|
+
rows?: number;
|
|
94
|
+
formGroup?: {
|
|
95
|
+
classes?: string;
|
|
96
|
+
attributes?: string | Record<string, string>;
|
|
97
|
+
};
|
|
98
|
+
components?: import("~/src/server/plugins/engine/components/types.js").ComponentViewModel[];
|
|
99
|
+
upload?: {
|
|
100
|
+
count: number;
|
|
101
|
+
summaryList: import("~/src/server/plugins/engine/types.js").SummaryList;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Validator factory for location-based fields.
|
|
106
|
+
* This creates a validator that ensures all required fields are present.
|
|
107
|
+
*/
|
|
108
|
+
export declare function createLocationFieldValidator(component: LocationField): CustomValidator;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { isFormValue } from "./FormComponent.js";
|
|
2
|
+
import { markdown } from "./markdownParser.js";
|
|
3
|
+
export function getLocationFieldViewModel(component, viewModel, payload, errors) {
|
|
4
|
+
const {
|
|
5
|
+
collection,
|
|
6
|
+
name
|
|
7
|
+
} = component;
|
|
8
|
+
const {
|
|
9
|
+
fieldset: existingFieldset,
|
|
10
|
+
label
|
|
11
|
+
} = viewModel;
|
|
12
|
+
|
|
13
|
+
// Check for component errors only
|
|
14
|
+
const hasError = errors?.some(error => error.name === name);
|
|
15
|
+
|
|
16
|
+
// Use the component collection to generate the subitems
|
|
17
|
+
const items = collection.getViewModel(payload, errors).map(({
|
|
18
|
+
model
|
|
19
|
+
}) => {
|
|
20
|
+
let {
|
|
21
|
+
label,
|
|
22
|
+
type,
|
|
23
|
+
value,
|
|
24
|
+
classes,
|
|
25
|
+
prefix,
|
|
26
|
+
suffix,
|
|
27
|
+
errorMessage
|
|
28
|
+
} = model;
|
|
29
|
+
if (label) {
|
|
30
|
+
label.toString = () => label.text; // Use string labels
|
|
31
|
+
}
|
|
32
|
+
if (hasError || errorMessage) {
|
|
33
|
+
classes = `${classes ?? ''} govuk-input--error`.trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Allow any `toString()`-able value so non-numeric
|
|
37
|
+
// values are shown alongside their error messages
|
|
38
|
+
if (!isFormValue(value)) {
|
|
39
|
+
value = undefined;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
label,
|
|
43
|
+
id: model.id,
|
|
44
|
+
name: model.name,
|
|
45
|
+
type,
|
|
46
|
+
value,
|
|
47
|
+
classes,
|
|
48
|
+
prefix,
|
|
49
|
+
suffix
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
const fieldset = existingFieldset ?? {
|
|
53
|
+
legend: {
|
|
54
|
+
text: label.text,
|
|
55
|
+
classes: 'govuk-fieldset__legend--m'
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const result = {
|
|
59
|
+
...viewModel,
|
|
60
|
+
fieldset,
|
|
61
|
+
items
|
|
62
|
+
};
|
|
63
|
+
if (component.options.instructionText) {
|
|
64
|
+
return {
|
|
65
|
+
...result,
|
|
66
|
+
instructionText: markdown.parse(component.options.instructionText, {
|
|
67
|
+
async: false
|
|
68
|
+
})
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Validator factory for location-based fields.
|
|
76
|
+
* This creates a validator that ensures all required fields are present.
|
|
77
|
+
*/
|
|
78
|
+
export function createLocationFieldValidator(component) {
|
|
79
|
+
return (payload, helpers) => {
|
|
80
|
+
const {
|
|
81
|
+
collection,
|
|
82
|
+
name,
|
|
83
|
+
options
|
|
84
|
+
} = component;
|
|
85
|
+
const values = component.getFormValueFromState(component.getStateFromValidForm(payload));
|
|
86
|
+
const context = {
|
|
87
|
+
missing: collection.keys,
|
|
88
|
+
key: name
|
|
89
|
+
};
|
|
90
|
+
if (!component.isState(values)) {
|
|
91
|
+
return options.required !== false ? helpers.error('object.required', context) : payload;
|
|
92
|
+
}
|
|
93
|
+
return payload;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=LocationFieldHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocationFieldHelpers.js","names":["isFormValue","markdown","getLocationFieldViewModel","component","viewModel","payload","errors","collection","name","fieldset","existingFieldset","label","hasError","some","error","items","getViewModel","map","model","type","value","classes","prefix","suffix","errorMessage","toString","text","trim","undefined","id","legend","result","options","instructionText","parse","async","createLocationFieldValidator","helpers","values","getFormValueFromState","getStateFromValidForm","context","missing","keys","key","isState","required"],"sources":["../../../../../src/server/plugins/engine/components/LocationFieldHelpers.ts"],"sourcesContent":["import { type Context, type CustomValidator } from 'joi'\n\nimport { type EastingNorthingField } from '~/src/server/plugins/engine/components/EastingNorthingField.js'\nimport { isFormValue } from '~/src/server/plugins/engine/components/FormComponent.js'\nimport { type LatLongField } from '~/src/server/plugins/engine/components/LatLongField.js'\nimport { markdown } from '~/src/server/plugins/engine/components/markdownParser.js'\nimport {\n type DateInputItem,\n type Label,\n type ViewModel\n} from '~/src/server/plugins/engine/components/types.js'\nimport {\n type FormPayload,\n type FormSubmissionError,\n type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport type LocationField =\n | InstanceType<typeof EastingNorthingField>\n | InstanceType<typeof LatLongField>\n\nexport function getLocationFieldViewModel(\n component: LocationField,\n viewModel: ViewModel & {\n label: Label\n id: string\n name: string\n value: FormValue\n },\n payload: FormPayload,\n errors?: FormSubmissionError[]\n) {\n const { collection, name } = component\n const { fieldset: existingFieldset, label } = viewModel\n\n // Check for component errors only\n const hasError = errors?.some((error) => error.name === name)\n\n // Use the component collection to generate the subitems\n const items: DateInputItem[] = collection\n .getViewModel(payload, errors)\n .map(({ model }): DateInputItem => {\n let { label, type, value, classes, prefix, suffix, errorMessage } = model\n\n if (label) {\n label.toString = () => label.text // Use string labels\n }\n\n if (hasError || errorMessage) {\n classes = `${classes ?? ''} govuk-input--error`.trim()\n }\n\n // Allow any `toString()`-able value so non-numeric\n // values are shown alongside their error messages\n if (!isFormValue(value)) {\n value = undefined\n }\n\n return {\n label,\n id: model.id,\n name: model.name,\n type,\n value,\n classes,\n prefix,\n suffix\n }\n })\n\n const fieldset = existingFieldset ?? {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const result = {\n ...viewModel,\n fieldset,\n items\n }\n\n if (component.options.instructionText) {\n return {\n ...result,\n instructionText: markdown.parse(component.options.instructionText, {\n async: false\n })\n }\n }\n\n return result\n}\n\n/**\n * Validator factory for location-based fields.\n * This creates a validator that ensures all required fields are present.\n */\nexport function createLocationFieldValidator(\n component: LocationField\n): CustomValidator {\n return (payload: FormPayload, helpers) => {\n const { collection, name, options } = component\n\n const values = component.getFormValueFromState(\n component.getStateFromValidForm(payload)\n )\n\n const context: Context = {\n missing: collection.keys,\n key: name\n }\n\n if (!component.isState(values)) {\n return options.required !== false\n ? helpers.error('object.required', context)\n : payload\n }\n\n return payload\n }\n}\n"],"mappings":"AAGA,SAASA,WAAW;AAEpB,SAASC,QAAQ;AAgBjB,OAAO,SAASC,yBAAyBA,CACvCC,SAAwB,EACxBC,SAKC,EACDC,OAAoB,EACpBC,MAA8B,EAC9B;EACA,MAAM;IAAEC,UAAU;IAAEC;EAAK,CAAC,GAAGL,SAAS;EACtC,MAAM;IAAEM,QAAQ,EAAEC,gBAAgB;IAAEC;EAAM,CAAC,GAAGP,SAAS;;EAEvD;EACA,MAAMQ,QAAQ,GAAGN,MAAM,EAAEO,IAAI,CAAEC,KAAK,IAAKA,KAAK,CAACN,IAAI,KAAKA,IAAI,CAAC;;EAE7D;EACA,MAAMO,KAAsB,GAAGR,UAAU,CACtCS,YAAY,CAACX,OAAO,EAAEC,MAAM,CAAC,CAC7BW,GAAG,CAAC,CAAC;IAAEC;EAAM,CAAC,KAAoB;IACjC,IAAI;MAAEP,KAAK;MAAEQ,IAAI;MAAEC,KAAK;MAAEC,OAAO;MAAEC,MAAM;MAAEC,MAAM;MAAEC;IAAa,CAAC,GAAGN,KAAK;IAEzE,IAAIP,KAAK,EAAE;MACTA,KAAK,CAACc,QAAQ,GAAG,MAAMd,KAAK,CAACe,IAAI,EAAC;IACpC;IAEA,IAAId,QAAQ,IAAIY,YAAY,EAAE;MAC5BH,OAAO,GAAG,GAAGA,OAAO,IAAI,EAAE,qBAAqB,CAACM,IAAI,CAAC,CAAC;IACxD;;IAEA;IACA;IACA,IAAI,CAAC3B,WAAW,CAACoB,KAAK,CAAC,EAAE;MACvBA,KAAK,GAAGQ,SAAS;IACnB;IAEA,OAAO;MACLjB,KAAK;MACLkB,EAAE,EAAEX,KAAK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,0 +1,19 @@
|
|
|
1
|
+
import { type NationalGridFieldNumberFieldComponent } from '@defra/forms-model';
|
|
2
|
+
import type joi from 'joi';
|
|
3
|
+
import { LocationFieldBase } from '~/src/server/plugins/engine/components/LocationFieldBase.js';
|
|
4
|
+
export declare class NationalGridFieldNumberField extends LocationFieldBase {
|
|
5
|
+
options: NationalGridFieldNumberFieldComponent['options'];
|
|
6
|
+
protected getValidationConfig(): {
|
|
7
|
+
pattern: RegExp;
|
|
8
|
+
patternErrorMessage: string;
|
|
9
|
+
customValidation: (value: string, helpers: joi.CustomHelpers) => string | joi.ErrorReport;
|
|
10
|
+
};
|
|
11
|
+
protected getErrorTemplates(): {
|
|
12
|
+
type: string;
|
|
13
|
+
template: string;
|
|
14
|
+
}[];
|
|
15
|
+
/**
|
|
16
|
+
* Static version of getAllPossibleErrors that doesn't require a component instance.
|
|
17
|
+
*/
|
|
18
|
+
static getAllPossibleErrors(): import("../types.js").ErrorMessageTemplateList;
|
|
19
|
+
}
|