@defra/forms-engine-plugin 4.0.23 → 4.0.25

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.
Files changed (48) hide show
  1. package/.server/server/forms/components.json +2 -2
  2. package/.server/server/plugins/engine/components/DeclarationField.d.ts +2 -0
  3. package/.server/server/plugins/engine/components/DeclarationField.js +8 -1
  4. package/.server/server/plugins/engine/components/DeclarationField.js.map +1 -1
  5. package/.server/server/plugins/engine/components/EastingNorthingField.js +7 -6
  6. package/.server/server/plugins/engine/components/EastingNorthingField.js.map +1 -1
  7. package/.server/server/plugins/engine/components/LatLongField.js +7 -6
  8. package/.server/server/plugins/engine/components/LatLongField.js.map +1 -1
  9. package/.server/server/plugins/engine/components/LocationFieldBase.d.ts +4 -4
  10. package/.server/server/plugins/engine/components/LocationFieldBase.js +3 -2
  11. package/.server/server/plugins/engine/components/LocationFieldBase.js.map +1 -1
  12. package/.server/server/plugins/engine/components/Markdown.d.ts +2 -0
  13. package/.server/server/plugins/engine/components/Markdown.js +4 -1
  14. package/.server/server/plugins/engine/components/Markdown.js.map +1 -1
  15. package/.server/server/plugins/engine/components/NationalGridFieldNumberField.d.ts +3 -3
  16. package/.server/server/plugins/engine/components/NationalGridFieldNumberField.js +5 -3
  17. package/.server/server/plugins/engine/components/NationalGridFieldNumberField.js.map +1 -1
  18. package/.server/server/plugins/engine/components/OsGridRefField.d.ts +3 -3
  19. package/.server/server/plugins/engine/components/OsGridRefField.js +5 -3
  20. package/.server/server/plugins/engine/components/OsGridRefField.js.map +1 -1
  21. package/.server/server/plugins/engine/components/helpers/index.d.ts +10 -0
  22. package/.server/server/plugins/engine/components/helpers/index.js +18 -0
  23. package/.server/server/plugins/engine/components/helpers/index.js.map +1 -1
  24. package/.server/server/plugins/engine/index.js +4 -1
  25. package/.server/server/plugins/engine/index.js.map +1 -1
  26. package/.server/server/plugins/engine/views/components/declarationfield.html +1 -1
  27. package/.server/server/plugins/engine/views/components/markdown.html +1 -1
  28. package/.server/server/plugins/engine/views/confirmation.html +1 -1
  29. package/package.json +3 -2
  30. package/src/server/forms/components.json +2 -2
  31. package/src/server/plugins/engine/components/DeclarationField.test.ts +24 -0
  32. package/src/server/plugins/engine/components/DeclarationField.ts +20 -2
  33. package/src/server/plugins/engine/components/EastingNorthingField.test.ts +30 -1
  34. package/src/server/plugins/engine/components/EastingNorthingField.ts +19 -6
  35. package/src/server/plugins/engine/components/LatLongField.test.ts +30 -1
  36. package/src/server/plugins/engine/components/LatLongField.ts +19 -6
  37. package/src/server/plugins/engine/components/LocationFieldBase.ts +11 -6
  38. package/src/server/plugins/engine/components/Markdown.ts +4 -1
  39. package/src/server/plugins/engine/components/NationalGridFieldNumberField.test.ts +4 -4
  40. package/src/server/plugins/engine/components/NationalGridFieldNumberField.ts +11 -4
  41. package/src/server/plugins/engine/components/OsGridRefField.test.ts +4 -4
  42. package/src/server/plugins/engine/components/OsGridRefField.ts +11 -3
  43. package/src/server/plugins/engine/components/helpers/helpers.test.ts +40 -0
  44. package/src/server/plugins/engine/components/helpers/index.ts +18 -0
  45. package/src/server/plugins/engine/index.ts +5 -2
  46. package/src/server/plugins/engine/views/components/declarationfield.html +1 -1
  47. package/src/server/plugins/engine/views/components/markdown.html +1 -1
  48. package/src/server/plugins/engine/views/confirmation.html +1 -1
@@ -139,7 +139,7 @@
139
139
  "type": "Markdown",
140
140
  "name": "markdown",
141
141
  "title": "Title",
142
- "content": "### This is a H3 in markdown\n\n[An internal link](http://localhost:3009/fictional-page)\n\n[An external link](https://defra.gov.uk/fictional-page)",
142
+ "content": "# Markdown - This is H1\n## This is H2\n### This is H3\n#### This is H4\n##### This is H5\n###### This is H6\n\n[An internal link](http://localhost:3009/fictional-page)\n\n[An external link](https://defra.gov.uk/fictional-page)",
143
143
  "options": {},
144
144
  "schema": {}
145
145
  },
@@ -147,7 +147,7 @@
147
147
  "type": "DeclarationField",
148
148
  "name": "declaration",
149
149
  "title": "Declaration",
150
- "content": "By submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements",
150
+ "content": "# H1\nBy submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements",
151
151
  "hint": "Please read and confirm the following terms",
152
152
  "options": {
153
153
  "required": false
@@ -9,6 +9,7 @@ export declare class DeclarationField extends FormComponent {
9
9
  formSchema: ArraySchema<StringSchema[]>;
10
10
  stateSchema: BooleanSchema;
11
11
  content: string;
12
+ headerStartLevel: number;
12
13
  constructor(def: DeclarationFieldComponent, props: ConstructorParameters<typeof FormComponent>[1]);
13
14
  getFormValueFromState(state: FormSubmissionState): "true" | "false";
14
15
  getFormDataFromState(state: FormSubmissionState): FormPayload;
@@ -30,6 +31,7 @@ export declare class DeclarationField extends FormComponent {
30
31
  value: string;
31
32
  checked: boolean;
32
33
  }[];
34
+ headerStartLevel: number;
33
35
  label: {
34
36
  text: string;
35
37
  };
@@ -1,8 +1,10 @@
1
+ import { ComponentType, hasFormComponents, isFormType } from '@defra/forms-model';
1
2
  import joi from 'joi';
2
3
  import { FormComponent, isFormValue } from "./FormComponent.js";
3
4
  import { messageTemplate } from "../pageControllers/validationOptions.js";
4
5
  export class DeclarationField extends FormComponent {
5
6
  DEFAULT_DECLARATION_LABEL = 'I understand and agree';
7
+ headerStartLevel;
6
8
  constructor(def, props) {
7
9
  super(def, props);
8
10
  const {
@@ -23,6 +25,10 @@ export class DeclarationField extends FormComponent {
23
25
  this.options = options;
24
26
  this.content = content;
25
27
  this.declarationConfirmationLabel = options.declarationConfirmationLabel ?? this.DEFAULT_DECLARATION_LABEL;
28
+ const formComponents = hasFormComponents(props.page?.pageDef) ? props.page.pageDef.components : [];
29
+ const numOfQuestionsOnPage = formComponents.filter(q => isFormType(q.type)).length;
30
+ const hasGuidance = formComponents.some((comp, idx) => comp.type === ComponentType.Markdown && idx === 0);
31
+ this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3;
26
32
  }
27
33
  getFormValueFromState(state) {
28
34
  const {
@@ -89,7 +95,8 @@ export class DeclarationField extends FormComponent {
89
95
  text: declarationConfirmationLabel,
90
96
  value: 'true',
91
97
  checked: isChecked
92
- }]
98
+ }],
99
+ headerStartLevel: this.headerStartLevel
93
100
  };
94
101
  }
95
102
  isValue(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"DeclarationField.js","names":["joi","FormComponent","isFormValue","messageTemplate","DeclarationField","DEFAULT_DECLARATION_LABEL","constructor","def","props","options","content","checkboxSchema","string","valid","required","formSchema","array","items","strip","label","single","messages","declarationRequired","stateSchema","boolean","cast","declarationConfirmationLabel","getFormValueFromState","state","name","getFormDataFromState","getStateFromValidForm","payload","payloadValue","value","isValue","length","every","v","getContextValueFromFormValue","getFormValue","undefined","getDisplayStringFromFormValue","getViewModel","errors","defaultDeclarationConfirmationLabel","hint","viewModel","fieldset","legend","text","classes","isChecked","checked","Array","isArray","getAllPossibleErrors","baseErrors","type","template","advancedSettingsErrors","isBool"],"sources":["../../../../../src/server/plugins/engine/components/DeclarationField.ts"],"sourcesContent":["import { type DeclarationFieldComponent, type Item } from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type StringSchema\n} from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.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 type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport class DeclarationField extends FormComponent {\n private readonly DEFAULT_DECLARATION_LABEL = 'I understand and agree'\n\n declare options: DeclarationFieldComponent['options']\n\n declare declarationConfirmationLabel: string\n\n declare formSchema: ArraySchema<StringSchema[]>\n declare stateSchema: BooleanSchema\n declare content: string\n\n constructor(\n def: DeclarationFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, content } = def\n\n let checkboxSchema = joi.string().valid('true')\n\n if (options.required !== false) {\n checkboxSchema = checkboxSchema.required()\n }\n\n const formSchema = joi\n .array()\n .items(checkboxSchema, joi.string().valid('unchecked').strip())\n .label(this.label)\n .single()\n .messages({\n 'any.required': messageTemplate.declarationRequired as string,\n 'any.unknown': messageTemplate.declarationRequired as string,\n 'array.includesRequiredUnknowns':\n messageTemplate.declarationRequired as string\n }) as ArraySchema<StringSchema[]>\n\n this.formSchema = formSchema\n this.stateSchema = joi.boolean().cast('string').label(this.label).required()\n\n this.options = options\n this.content = content\n this.declarationConfirmationLabel =\n options.declarationConfirmationLabel ?? this.DEFAULT_DECLARATION_LABEL\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return state[name] === true ? 'true' : 'false'\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { name } = this\n return { [name]: state[name] === true ? 'true' : 'false' }\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { name } = this\n const payloadValue = payload[name]\n const value =\n this.isValue(payloadValue) &&\n payloadValue.length > 0 &&\n payloadValue.every((v) => {\n return v === 'true'\n })\n\n return { [name]: value }\n }\n\n getContextValueFromFormValue(value: FormValue | FormPayload): boolean {\n return value === 'true'\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(value: FormValue | FormPayload): string {\n return value === 'true' ? this.declarationConfirmationLabel : 'Not provided'\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const defaultDeclarationConfirmationLabel =\n 'I confirm that I understand and accept this declaration'\n const {\n hint,\n content,\n declarationConfirmationLabel = defaultDeclarationConfirmationLabel\n } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const isChecked =\n payload[this.name] === 'true' || payload[this.name] === true\n return {\n ...viewModel,\n hint: hint ? { text: hint } : undefined,\n fieldset,\n content,\n items: [\n {\n text: declarationConfirmationLabel,\n value: 'true',\n checked: isChecked\n }\n ]\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is Item['value'][] {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isFormValue)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DeclarationField.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.declarationRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isBool(value?: FormStateValue | FormState): value is boolean {\n return isFormValue(value) && typeof value === 'boolean'\n }\n}\n"],"mappings":"AACA,OAAOA,GAAG,MAIH,KAAK;AAEZ,SACEC,aAAa,EACbC,WAAW;AAEb,SAASC,eAAe;AAWxB,OAAO,MAAMC,gBAAgB,SAASH,aAAa,CAAC;EACjCI,yBAAyB,GAAG,wBAAwB;EAUrEC,WAAWA,CACTC,GAA8B,EAC9BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,OAAO;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAEhC,IAAII,cAAc,GAAGX,GAAG,CAACY,MAAM,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM,CAAC;IAE/C,IAAIJ,OAAO,CAACK,QAAQ,KAAK,KAAK,EAAE;MAC9BH,cAAc,GAAGA,cAAc,CAACG,QAAQ,CAAC,CAAC;IAC5C;IAEA,MAAMC,UAAU,GAAGf,GAAG,CACnBgB,KAAK,CAAC,CAAC,CACPC,KAAK,CAACN,cAAc,EAAEX,GAAG,CAACY,MAAM,CAAC,CAAC,CAACC,KAAK,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O,EAAED;MACX,CAAC;IAEL,CAAC;EACH;EAEAjB,OAAOA,CAACD,KAAkC,EAA4B;IACpE,IAAI,CAACoB,KAAK,CAACC,OAAO,CAACrB,KAAK,CAAC,EAAE;MACzB,OAAO,KAAK;IACd;;IAEA;IACA,IAAI,CAACA,KAAK,CAACE,MAAM,EAAE;MACjB,OAAO,IAAI;IACb;IAEA,OAAOF,KAAK,CAACG,KAAK,CAACnC,WAAW,CAAC;EACjC;;EAEA;AACF;AACA;EACEsD,oBAAoBA,CAAA,EAA6B;IAC/C,OAAOpD,gBAAgB,CAACoD,oBAAoB,CAAC,CAAC;EAChD;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QAAEC,IAAI,EAAE,UAAU;QAAEC,QAAQ,EAAExD,eAAe,CAACmB;MAAoB,CAAC,CACpE;MACDsC,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOC,MAAMA,CAAC3B,KAAkC,EAAoB;IAClE,OAAOhC,WAAW,CAACgC,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,SAAS;EACzD;AACF","ignoreList":[]}
1
+ {"version":3,"file":"DeclarationField.js","names":["ComponentType","hasFormComponents","isFormType","joi","FormComponent","isFormValue","messageTemplate","DeclarationField","DEFAULT_DECLARATION_LABEL","headerStartLevel","constructor","def","props","options","content","checkboxSchema","string","valid","required","formSchema","array","items","strip","label","single","messages","declarationRequired","stateSchema","boolean","cast","declarationConfirmationLabel","formComponents","page","pageDef","components","numOfQuestionsOnPage","filter","q","type","length","hasGuidance","some","comp","idx","Markdown","getFormValueFromState","state","name","getFormDataFromState","getStateFromValidForm","payload","payloadValue","value","isValue","every","v","getContextValueFromFormValue","getFormValue","undefined","getDisplayStringFromFormValue","getViewModel","errors","defaultDeclarationConfirmationLabel","hint","viewModel","fieldset","legend","text","classes","isChecked","checked","Array","isArray","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isBool"],"sources":["../../../../../src/server/plugins/engine/components/DeclarationField.ts"],"sourcesContent":["import {\n ComponentType,\n hasFormComponents,\n isFormType,\n type DeclarationFieldComponent,\n type Item\n} from '@defra/forms-model'\nimport joi, {\n type ArraySchema,\n type BooleanSchema,\n type StringSchema\n} from 'joi'\n\nimport {\n FormComponent,\n isFormValue\n} from '~/src/server/plugins/engine/components/FormComponent.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 type FormValue\n} from '~/src/server/plugins/engine/types.js'\n\nexport class DeclarationField extends FormComponent {\n private readonly DEFAULT_DECLARATION_LABEL = 'I understand and agree'\n\n declare options: DeclarationFieldComponent['options']\n\n declare declarationConfirmationLabel: string\n\n declare formSchema: ArraySchema<StringSchema[]>\n declare stateSchema: BooleanSchema\n declare content: string\n headerStartLevel: number\n\n constructor(\n def: DeclarationFieldComponent,\n props: ConstructorParameters<typeof FormComponent>[1]\n ) {\n super(def, props)\n\n const { options, content } = def\n\n let checkboxSchema = joi.string().valid('true')\n\n if (options.required !== false) {\n checkboxSchema = checkboxSchema.required()\n }\n\n const formSchema = joi\n .array()\n .items(checkboxSchema, joi.string().valid('unchecked').strip())\n .label(this.label)\n .single()\n .messages({\n 'any.required': messageTemplate.declarationRequired as string,\n 'any.unknown': messageTemplate.declarationRequired as string,\n 'array.includesRequiredUnknowns':\n messageTemplate.declarationRequired as string\n }) as ArraySchema<StringSchema[]>\n\n this.formSchema = formSchema\n this.stateSchema = joi.boolean().cast('string').label(this.label).required()\n\n this.options = options\n this.content = content\n this.declarationConfirmationLabel =\n options.declarationConfirmationLabel ?? this.DEFAULT_DECLARATION_LABEL\n const formComponents = hasFormComponents(props.page?.pageDef)\n ? props.page.pageDef.components\n : []\n const numOfQuestionsOnPage = formComponents.filter((q) =>\n isFormType(q.type)\n ).length\n const hasGuidance = formComponents.some(\n (comp, idx) => comp.type === ComponentType.Markdown && idx === 0\n )\n this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3\n }\n\n getFormValueFromState(state: FormSubmissionState) {\n const { name } = this\n return state[name] === true ? 'true' : 'false'\n }\n\n getFormDataFromState(state: FormSubmissionState): FormPayload {\n const { name } = this\n return { [name]: state[name] === true ? 'true' : 'false' }\n }\n\n getStateFromValidForm(payload: FormPayload): FormState {\n const { name } = this\n const payloadValue = payload[name]\n const value =\n this.isValue(payloadValue) &&\n payloadValue.length > 0 &&\n payloadValue.every((v) => {\n return v === 'true'\n })\n\n return { [name]: value }\n }\n\n getContextValueFromFormValue(value: FormValue | FormPayload): boolean {\n return value === 'true'\n }\n\n getFormValue(value?: FormStateValue | FormState) {\n return this.isValue(value) ? value : undefined\n }\n\n getDisplayStringFromFormValue(value: FormValue | FormPayload): string {\n return value === 'true' ? this.declarationConfirmationLabel : 'Not provided'\n }\n\n getViewModel(payload: FormPayload, errors?: FormSubmissionError[]) {\n const defaultDeclarationConfirmationLabel =\n 'I confirm that I understand and accept this declaration'\n const {\n hint,\n content,\n declarationConfirmationLabel = defaultDeclarationConfirmationLabel\n } = this\n\n const viewModel = super.getViewModel(payload, errors)\n let { fieldset, label } = viewModel\n\n fieldset ??= {\n legend: {\n text: label.text,\n classes: 'govuk-fieldset__legend--m'\n }\n }\n\n const isChecked =\n payload[this.name] === 'true' || payload[this.name] === true\n return {\n ...viewModel,\n hint: hint ? { text: hint } : undefined,\n fieldset,\n content,\n items: [\n {\n text: declarationConfirmationLabel,\n value: 'true',\n checked: isChecked\n }\n ],\n headerStartLevel: this.headerStartLevel\n }\n }\n\n isValue(value?: FormStateValue | FormState): value is Item['value'][] {\n if (!Array.isArray(value)) {\n return false\n }\n\n // Skip checks when empty\n if (!value.length) {\n return true\n }\n\n return value.every(isFormValue)\n }\n\n /**\n * For error preview page that shows all possible errors on a component\n */\n getAllPossibleErrors(): ErrorMessageTemplateList {\n return DeclarationField.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.declarationRequired }\n ],\n advancedSettingsErrors: []\n }\n }\n\n static isBool(value?: FormStateValue | FormState): value is boolean {\n return isFormValue(value) && typeof value === 'boolean'\n }\n}\n"],"mappings":"AAAA,SACEA,aAAa,EACbC,iBAAiB,EACjBC,UAAU,QAGL,oBAAoB;AAC3B,OAAOC,GAAG,MAIH,KAAK;AAEZ,SACEC,aAAa,EACbC,WAAW;AAEb,SAASC,eAAe;AAWxB,OAAO,MAAMC,gBAAgB,SAASH,aAAa,CAAC;EACjCI,yBAAyB,GAAG,wBAAwB;EASrEC,gBAAgB;EAEhBC,WAAWA,CACTC,GAA8B,EAC9BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,OAAO;MAAEC;IAAQ,CAAC,GAAGH,GAAG;IAEhC,IAAII,cAAc,GAAGZ,GAAG,CAACa,MAAM,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM,CAAC;IAE/C,IAAIJ,OAAO,CAACK,QAAQ,KAAK,KAAK,EAAE;MAC9BH,cAAc,GAAGA,cAAc,CAACG,QAAQ,CAAC,CAAC;IAC5C;IAEA,MAAMC,UAAU,GAAGhB,GAAG,CACnBiB,KAAK,CAAC,CAAC,CACPC,KAAK,CAACN,cAAc,EAAEZ,GAAG,CAACa,MAAM,CAAC,CAAC,CAACC,KAAK,CAAC,WAAW,CAAC,CAACK,KAAK,CAAC,CAAC,CAAC,CAC9DC,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CACjBC,MAAM,CAAC,CAAC,CACRC,QAAQ,CAAC;MACR,cAAc,EAAEnB,eAAe,CAACoB,mBAA6B;MAC7D,aAAa,EAAEpB,eAAe,CAACoB,mBAA6B;MAC5D,gCAAgC,EAC9BpB,eAAe,C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IG,OAAO,CAAC,IAAI,CAACH,IAAI,CAAC,KAAK,IAAI;IAC9D,OAAO;MACL,GAAGiB,SAAS;MACZD,IAAI,EAAEA,IAAI,GAAG;QAAEI,IAAI,EAAEJ;MAAK,CAAC,GAAGL,SAAS;MACvCO,QAAQ;MACRnD,OAAO;MACPO,KAAK,EAAE,CACL;QACE8C,IAAI,EAAErC,4BAA4B;QAClCsB,KAAK,EAAE,MAAM;QACbkB,OAAO,EAAED;MACX,CAAC,CACF;MACD5D,gBAAgB,EAAE,IAAI,CAACA;IACzB,CAAC;EACH;EAEA4C,OAAOA,CAACD,KAAkC,EAA4B;IACpE,IAAI,CAACmB,KAAK,CAACC,OAAO,CAACpB,KAAK,CAAC,EAAE;MACzB,OAAO,KAAK;IACd;;IAEA;IACA,IAAI,CAACA,KAAK,CAACb,MAAM,EAAE;MACjB,OAAO,IAAI;IACb;IAEA,OAAOa,KAAK,CAACE,KAAK,CAACjD,WAAW,CAAC;EACjC;;EAEA;AACF;AACA;EACEoE,oBAAoBA,CAAA,EAA6B;IAC/C,OAAOlE,gBAAgB,CAACkE,oBAAoB,CAAC,CAAC;EAChD;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QAAEpC,IAAI,EAAE,UAAU;QAAEqC,QAAQ,EAAErE,eAAe,CAACoB;MAAoB,CAAC,CACpE;MACDkD,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOC,MAAMA,CAACzB,KAAkC,EAAoB;IAClE,OAAO/C,WAAW,CAAC+C,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,SAAS;EACzD;AACF","ignoreList":[]}
@@ -4,6 +4,7 @@ import { ComponentCollection } from "./ComponentCollection.js";
4
4
  import { FormComponent, isFormState } from "./FormComponent.js";
5
5
  import { deduplicateErrorsByHref, getLocationFieldViewModel } from "./LocationFieldHelpers.js";
6
6
  import { NumberField } from "./NumberField.js";
7
+ import { createLowerFirstExpression } from "./helpers/index.js";
7
8
  import { messageTemplate } from "../pageControllers/validationOptions.js";
8
9
  import { convertToLanguageMessages } from "../../../utils/type-utils.js";
9
10
 
@@ -142,23 +143,23 @@ export class EastingNorthingField extends FormComponent {
142
143
  template: messageTemplate.required
143
144
  }, {
144
145
  type: 'eastingFormat',
145
- template: 'Easting for {{#title}} must be between 1 and 6 digits'
146
+ template: createLowerFirstExpression('Easting for {{lowerFirst(#title)}} must be between 1 and 6 digits')
146
147
  }, {
147
148
  type: 'northingFormat',
148
- template: 'Northing for {{#title}} must be between 1 and 7 digits'
149
+ template: createLowerFirstExpression('Northing for {{lowerFirst(#title)}} must be between 1 and 7 digits')
149
150
  }],
150
151
  advancedSettingsErrors: [{
151
152
  type: 'eastingMin',
152
- template: `Easting for {{#title}} must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`
153
+ template: createLowerFirstExpression(`Easting for {{lowerFirst(#title)}} must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`)
153
154
  }, {
154
155
  type: 'eastingMax',
155
- template: `Easting for {{#title}} must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`
156
+ template: createLowerFirstExpression(`Easting for {{lowerFirst(#title)}} must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`)
156
157
  }, {
157
158
  type: 'northingMin',
158
- template: `Northing for {{#title}} must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`
159
+ template: createLowerFirstExpression(`Northing for {{lowerFirst(#title)}} must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`)
159
160
  }, {
160
161
  type: 'northingMax',
161
- template: `Northing for {{#title}} must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`
162
+ template: createLowerFirstExpression(`Northing for {{lowerFirst(#title)}} must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`)
162
163
  }]
163
164
  };
164
165
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EastingNorthingField.js","names":["ComponentType","lowerFirst","ComponentCollection","FormComponent","isFormState","deduplicateErrorsByHref","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","eastingRequired","northingRequired","eastingDigitsMessage","label","northingDigitsMessage","customValidationMessages","northingValidationMessages","collection","type","title","precision","optionalText","classes","parent","peers","formSchema","stateSchema","getFormValueFromState","state","value","isEastingNorthing","undefined","getDisplayStringFromFormValue","getDisplayStringFromState","getContextValueFromFormValue","getContextValueFromState","getViewModel","payload","errors","viewModel","getViewErrors","allErrors","getErrors","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isNumber"],"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'\nimport lowerFirst from 'lodash/lowerFirst.js'\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 deduplicateErrorsByHref,\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 = 700000\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 eastingRequired = 'Enter easting'\n const northingRequired = 'Enter northing'\n\n const eastingDigitsMessage = `{{#label}} for ${lowerFirst(this.label)} must be between 1 and 6 digits`\n const northingDigitsMessage = `{{#label}} for ${lowerFirst(this.label)} must be between 1 and 7 digits`\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n 'any.required': eastingRequired,\n 'number.base': eastingRequired,\n 'number.min': `{{#label}} for ${lowerFirst(this.label)} must be between {{#limit}} and ${eastingMax}`,\n 'number.max': `{{#label}} for ${lowerFirst(this.label)} must be between ${eastingMin} and {{#limit}}`,\n 'number.precision': eastingDigitsMessage,\n 'number.integer': eastingDigitsMessage,\n 'number.unsafe': eastingDigitsMessage\n })\n\n const northingValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n 'any.required': northingRequired,\n 'number.base': northingRequired,\n 'number.min': `{{#label}} for ${lowerFirst(this.label)} must be between {{#limit}} and ${northingMax}`,\n 'number.max': `{{#label}} for ${lowerFirst(this.label)} must be between ${northingMin} and {{#limit}}`,\n 'number.precision': northingDigitsMessage,\n 'number.integer': northingDigitsMessage,\n 'number.unsafe': northingDigitsMessage\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__easting`,\n title: 'Easting',\n schema: {\n min: eastingMin,\n max: eastingMax,\n precision: 0\n },\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: {\n min: northingMin,\n max: northingMax,\n precision: 0\n },\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 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: <<eastingvalue, northingvalue>>\n return `${value.easting}, ${value.northing}`\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 return `Easting: ${value.easting}\\nNorthing: ${value.northing}`\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 getViewErrors(\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const allErrors = this.getErrors(errors)\n return deduplicateErrorsByHref(allErrors)\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: 'Easting for {{#title}} must be between 1 and 6 digits'\n },\n {\n type: 'northingFormat',\n template: 'Northing for {{#title}} must be between 1 and 7 digits'\n }\n ],\n advancedSettingsErrors: [\n {\n type: 'eastingMin',\n template: `Easting for {{#title}} must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`\n },\n {\n type: 'eastingMax',\n template: `Easting for {{#title}} must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`\n },\n {\n type: 'northingMin',\n template: `Northing for {{#title}} must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`\n },\n {\n type: 'northingMax',\n template: `Northing for {{#title}} 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"],"mappings":"AAAA,SACEA,aAAa,QAER,oBAAoB;AAE3B,OAAOC,UAAU,MAAM,sBAAsB;AAE7C,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW;AAEb,SACEC,uBAAuB,EACvBC,yBAAyB;AAE3B,SAASC,WAAW;AAEpB,SAASC,eAAe;AASxB,SAASC,yBAAyB;;AAElC;AACA,MAAMC,mBAAmB,GAAG,CAAC;AAC7B,MAAMC,mBAAmB,GAAG,MAAM;AAClC,MAAMC,oBAAoB,GAAG,CAAC;AAC9B,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CAAC1B,OAAO,CAAC,IACnCjB,WAAW,CAAC8D,QAAQ,CAACnB,KAAK,CAACrB,QAAQ,CAAC;EAExC;AACF","ignoreList":[]}
1
+ {"version":3,"file":"EastingNorthingField.js","names":["ComponentType","lowerFirst","ComponentCollection","FormComponent","isFormState","deduplicateErrorsByHref","getLocationFieldViewModel","NumberField","createLowerFirstExpression","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","eastingRequired","northingRequired","eastingDigitsMessage","label","northingDigitsMessage","customValidationMessages","northingValidationMessages","collection","type","title","precision","optionalText","classes","parent","peers","formSchema","stateSchema","getFormValueFromState","state","value","isEastingNorthing","undefined","getDisplayStringFromFormValue","getDisplayStringFromState","getContextValueFromFormValue","getContextValueFromState","getViewModel","payload","errors","viewModel","getViewErrors","allErrors","getErrors","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isNumber"],"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'\nimport lowerFirst from 'lodash/lowerFirst.js'\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 deduplicateErrorsByHref,\n getLocationFieldViewModel\n} from '~/src/server/plugins/engine/components/LocationFieldHelpers.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport { createLowerFirstExpression } from '~/src/server/plugins/engine/components/helpers/index.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 = 700000\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 eastingRequired = 'Enter easting'\n const northingRequired = 'Enter northing'\n\n const eastingDigitsMessage = `{{#label}} for ${lowerFirst(this.label)} must be between 1 and 6 digits`\n const northingDigitsMessage = `{{#label}} for ${lowerFirst(this.label)} must be between 1 and 7 digits`\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n 'any.required': eastingRequired,\n 'number.base': eastingRequired,\n 'number.min': `{{#label}} for ${lowerFirst(this.label)} must be between {{#limit}} and ${eastingMax}`,\n 'number.max': `{{#label}} for ${lowerFirst(this.label)} must be between ${eastingMin} and {{#limit}}`,\n 'number.precision': eastingDigitsMessage,\n 'number.integer': eastingDigitsMessage,\n 'number.unsafe': eastingDigitsMessage\n })\n\n const northingValidationMessages: LanguageMessages =\n convertToLanguageMessages({\n 'any.required': northingRequired,\n 'number.base': northingRequired,\n 'number.min': `{{#label}} for ${lowerFirst(this.label)} must be between {{#limit}} and ${northingMax}`,\n 'number.max': `{{#label}} for ${lowerFirst(this.label)} must be between ${northingMin} and {{#limit}}`,\n 'number.precision': northingDigitsMessage,\n 'number.integer': northingDigitsMessage,\n 'number.unsafe': northingDigitsMessage\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__easting`,\n title: 'Easting',\n schema: {\n min: eastingMin,\n max: eastingMax,\n precision: 0\n },\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: {\n min: northingMin,\n max: northingMax,\n precision: 0\n },\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 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: <<eastingvalue, northingvalue>>\n return `${value.easting}, ${value.northing}`\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 return `Easting: ${value.easting}\\nNorthing: ${value.northing}`\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 getViewErrors(\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const allErrors = this.getErrors(errors)\n return deduplicateErrorsByHref(allErrors)\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: createLowerFirstExpression(\n 'Easting for {{lowerFirst(#title)}} must be between 1 and 6 digits'\n )\n },\n {\n type: 'northingFormat',\n template: createLowerFirstExpression(\n 'Northing for {{lowerFirst(#title)}} must be between 1 and 7 digits'\n )\n }\n ],\n advancedSettingsErrors: [\n {\n type: 'eastingMin',\n template: createLowerFirstExpression(\n `Easting for {{lowerFirst(#title)}} must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`\n )\n },\n {\n type: 'eastingMax',\n template: createLowerFirstExpression(\n `Easting for {{lowerFirst(#title)}} must be between ${DEFAULT_EASTING_MIN} and ${DEFAULT_EASTING_MAX}`\n )\n },\n {\n type: 'northingMin',\n template: createLowerFirstExpression(\n `Northing for {{lowerFirst(#title)}} must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`\n )\n },\n {\n type: 'northingMax',\n template: createLowerFirstExpression(\n `Northing for {{lowerFirst(#title)}} must be between ${DEFAULT_NORTHING_MIN} and ${DEFAULT_NORTHING_MAX}`\n )\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"],"mappings":"AAAA,SACEA,aAAa,QAER,oBAAoB;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AA0B,CAClC,sDAAsDG,mBAAmB,QAAQC,mBAAmB,EACtG;MACF,CAAC,EACD;QACE4B,IAAI,EAAE,aAAa;QACnB4B,QAAQ,EAAE5D,0BAA0B,CAClC,uDAAuDK,oBAAoB,QAAQC,oBAAoB,EACzG;MACF,CAAC,EACD;QACE0B,IAAI,EAAE,aAAa;QACnB4B,QAAQ,EAAE5D,0BAA0B,CAClC,uDAAuDK,oBAAoB,QAAQC,oBAAoB,EACzG;MACF,CAAC;IAEL,CAAC;EACH;EAEA,OAAOsC,iBAAiBA,CACtBD,KAAkC,EACH;IAC/B,OACE/C,WAAW,CAAC+C,KAAK,CAAC,IAClB5C,WAAW,CAAC+D,QAAQ,CAACnB,KAAK,CAAC1B,OAAO,CAAC,IACnClB,WAAW,CAAC+D,QAAQ,CAACnB,KAAK,CAACrB,QAAQ,CAAC;EAExC;AACF","ignoreList":[]}
@@ -4,6 +4,7 @@ import { ComponentCollection } from "./ComponentCollection.js";
4
4
  import { FormComponent, isFormState } from "./FormComponent.js";
5
5
  import { deduplicateErrorsByHref, getLocationFieldViewModel } from "./LocationFieldHelpers.js";
6
6
  import { NumberField } from "./NumberField.js";
7
+ import { createLowerFirstExpression } from "./helpers/index.js";
7
8
  import { messageTemplate } from "../pageControllers/validationOptions.js";
8
9
  import { convertToLanguageMessages } from "../../../utils/type-utils.js";
9
10
 
@@ -147,23 +148,23 @@ export class LatLongField extends FormComponent {
147
148
  template: messageTemplate.required
148
149
  }, {
149
150
  type: 'latitudeFormat',
150
- template: 'Enter a valid latitude for {{#title}} like 51.519450'
151
+ template: createLowerFirstExpression('Enter a valid latitude for {{lowerFirst(#title)}} like 51.519450')
151
152
  }, {
152
153
  type: 'longitudeFormat',
153
- template: 'Enter a valid longitude for {{#title}} like -0.127758'
154
+ template: createLowerFirstExpression('Enter a valid longitude for {{lowerFirst(#title)}} like -0.127758')
154
155
  }],
155
156
  advancedSettingsErrors: [{
156
157
  type: 'latitudeMin',
157
- template: 'Latitude for {{#title}} must be between 49 and 60'
158
+ template: createLowerFirstExpression('Latitude for {{lowerFirst(#title)}} must be between 49 and 60')
158
159
  }, {
159
160
  type: 'latitudeMax',
160
- template: 'Latitude for {{#title}} must be between 49 and 60'
161
+ template: createLowerFirstExpression('Latitude for {{lowerFirst(#title)}} must be between 49 and 60')
161
162
  }, {
162
163
  type: 'longitudeMin',
163
- template: 'Longitude for {{#title}} must be between -9 and 2'
164
+ template: createLowerFirstExpression('Longitude for {{lowerFirst(#title)}} must be between -9 and 2')
164
165
  }, {
165
166
  type: 'longitudeMax',
166
- template: 'Longitude for {{#title}} must be between -9 and 2'
167
+ template: createLowerFirstExpression('Longitude for {{lowerFirst(#title)}} must be between -9 and 2')
167
168
  }]
168
169
  };
169
170
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LatLongField.js","names":["ComponentType","lowerFirst","ComponentCollection","FormComponent","isFormState","deduplicateErrorsByHref","getLocationFieldViewModel","NumberField","messageTemplate","convertToLanguageMessages","DECIMAL_PRECISION","LatLongField","constructor","def","props","name","options","schema","isRequired","required","latitudeMin","latitude","min","latitudeMax","max","longitudeMin","longitude","longitudeMax","latitudeRequired","longitudeRequired","customValidationMessages","latitudeRangeMessage","label","longitudeRangeMessage","latitudeMessages","longitudeMessages","collection","type","title","precision","optionalText","classes","suffix","parent","peers","formSchema","stateSchema","getFormValueFromState","state","value","isLatLong","undefined","getDisplayStringFromFormValue","getDisplayStringFromState","getContextValueFromFormValue","getContextValueFromState","getViewModel","payload","errors","viewModel","getViewErrors","allErrors","getErrors","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isNumber"],"sources":["../../../../../src/server/plugins/engine/components/LatLongField.ts"],"sourcesContent":["import { ComponentType, type LatLongFieldComponent } from '@defra/forms-model'\nimport { type LanguageMessages, type ObjectSchema } from 'joi'\nimport lowerFirst from 'lodash/lowerFirst.js'\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 deduplicateErrorsByHref,\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\n// Precision constants\n// UK latitude/longitude requires high precision for accurate location (within ~11mm)\nconst DECIMAL_PRECISION = 7 // 7 decimal places\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.85\n const latitudeMax = schema?.latitude?.max ?? 60.859\n const longitudeMin = schema?.longitude?.min ?? -13.687\n const longitudeMax = schema?.longitude?.max ?? 1.767\n\n const latitudeRequired = 'Enter latitude'\n const longitudeRequired = 'Enter longitude'\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\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 latitudeRangeMessage = `Latitude for ${lowerFirst(this.label)} must be between ${latitudeMin} and ${latitudeMax}`\n const longitudeRangeMessage = `Longitude for ${lowerFirst(this.label)} must be between ${longitudeMin} and ${longitudeMax}`\n\n const latitudeMessages: LanguageMessages = convertToLanguageMessages({\n ...customValidationMessages,\n 'any.required': latitudeRequired,\n 'number.base': `Enter a valid latitude for ${lowerFirst(this.label)} like 51.519450`,\n 'number.min': latitudeRangeMessage,\n 'number.max': latitudeRangeMessage\n })\n\n const longitudeMessages: LanguageMessages = convertToLanguageMessages({\n ...customValidationMessages,\n 'any.required': longitudeRequired,\n 'number.base': `Enter a valid longitude for ${lowerFirst(this.label)} like -0.127758`,\n 'number.min': longitudeRangeMessage,\n 'number.max': longitudeRangeMessage\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__latitude`,\n title: 'Latitude',\n schema: {\n min: latitudeMin,\n max: latitudeMax,\n precision: DECIMAL_PRECISION\n },\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: {\n min: longitudeMin,\n max: longitudeMax,\n precision: DECIMAL_PRECISION\n },\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 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: Latitude: <<entry>>\\nLongitude: <<entry>>\n return `Latitude: ${value.latitude}\\nLongitude: ${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 getViewErrors(\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const allErrors = this.getErrors(errors)\n return deduplicateErrorsByHref(allErrors)\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: 'Enter a valid latitude for {{#title}} like 51.519450'\n },\n {\n type: 'longitudeFormat',\n template: 'Enter a valid longitude for {{#title}} like -0.127758'\n }\n ],\n advancedSettingsErrors: [\n {\n type: 'latitudeMin',\n template: 'Latitude for {{#title}} must be between 49 and 60'\n },\n {\n type: 'latitudeMax',\n template: 'Latitude for {{#title}} must be between 49 and 60'\n },\n {\n type: 'longitudeMin',\n template: 'Longitude for {{#title}} must be between -9 and 2'\n },\n {\n type: 'longitudeMax',\n template: 'Longitude for {{#title}} 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"],"mappings":"AAAA,SAASA,aAAa,QAAoC,oBAAoB;AAE9E,OAAOC,UAAU,MAAM,sBAAsB;AAE7C,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW;AAEb,SACEC,uBAAuB,EACvBC,yBAAyB;AAE3B,SAASC,WAAW;AAE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.js","names":["ComponentType","lowerFirst","ComponentCollection","FormComponent","isFormState","deduplicateErrorsByHref","getLocationFieldViewModel","NumberField","createLowerFirstExpression","messageTemplate","convertToLanguageMessages","DECIMAL_PRECISION","LatLongField","constructor","def","props","name","options","schema","isRequired","required","latitudeMin","latitude","min","latitudeMax","max","longitudeMin","longitude","longitudeMax","latitudeRequired","longitudeRequired","customValidationMessages","latitudeRangeMessage","label","longitudeRangeMessage","latitudeMessages","longitudeMessages","collection","type","title","precision","optionalText","classes","suffix","parent","peers","formSchema","stateSchema","getFormValueFromState","state","value","isLatLong","undefined","getDisplayStringFromFormValue","getDisplayStringFromState","getContextValueFromFormValue","getContextValueFromState","getViewModel","payload","errors","viewModel","getViewErrors","allErrors","getErrors","isState","getAllPossibleErrors","baseErrors","template","advancedSettingsErrors","isNumber"],"sources":["../../../../../src/server/plugins/engine/components/LatLongField.ts"],"sourcesContent":["import { ComponentType, type LatLongFieldComponent } from '@defra/forms-model'\nimport { type LanguageMessages, type ObjectSchema } from 'joi'\nimport lowerFirst from 'lodash/lowerFirst.js'\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 deduplicateErrorsByHref,\n getLocationFieldViewModel\n} from '~/src/server/plugins/engine/components/LocationFieldHelpers.js'\nimport { NumberField } from '~/src/server/plugins/engine/components/NumberField.js'\nimport { createLowerFirstExpression } from '~/src/server/plugins/engine/components/helpers/index.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\n// Precision constants\n// UK latitude/longitude requires high precision for accurate location (within ~11mm)\nconst DECIMAL_PRECISION = 7 // 7 decimal places\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.85\n const latitudeMax = schema?.latitude?.max ?? 60.859\n const longitudeMin = schema?.longitude?.min ?? -13.687\n const longitudeMax = schema?.longitude?.max ?? 1.767\n\n const latitudeRequired = 'Enter latitude'\n const longitudeRequired = 'Enter longitude'\n\n const customValidationMessages: LanguageMessages =\n convertToLanguageMessages({\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 latitudeRangeMessage = `Latitude for ${lowerFirst(this.label)} must be between ${latitudeMin} and ${latitudeMax}`\n const longitudeRangeMessage = `Longitude for ${lowerFirst(this.label)} must be between ${longitudeMin} and ${longitudeMax}`\n\n const latitudeMessages: LanguageMessages = convertToLanguageMessages({\n ...customValidationMessages,\n 'any.required': latitudeRequired,\n 'number.base': `Enter a valid latitude for ${lowerFirst(this.label)} like 51.519450`,\n 'number.min': latitudeRangeMessage,\n 'number.max': latitudeRangeMessage\n })\n\n const longitudeMessages: LanguageMessages = convertToLanguageMessages({\n ...customValidationMessages,\n 'any.required': longitudeRequired,\n 'number.base': `Enter a valid longitude for ${lowerFirst(this.label)} like -0.127758`,\n 'number.min': longitudeRangeMessage,\n 'number.max': longitudeRangeMessage\n })\n\n this.collection = new ComponentCollection(\n [\n {\n type: ComponentType.NumberField,\n name: `${name}__latitude`,\n title: 'Latitude',\n schema: {\n min: latitudeMin,\n max: latitudeMax,\n precision: DECIMAL_PRECISION\n },\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: {\n min: longitudeMin,\n max: longitudeMax,\n precision: DECIMAL_PRECISION\n },\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 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: Latitude: <<entry>>\\nLongitude: <<entry>>\n return `Latitude: ${value.latitude}\\nLongitude: ${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 getViewErrors(\n errors?: FormSubmissionError[]\n ): FormSubmissionError[] | undefined {\n const allErrors = this.getErrors(errors)\n return deduplicateErrorsByHref(allErrors)\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: createLowerFirstExpression(\n 'Enter a valid latitude for {{lowerFirst(#title)}} like 51.519450'\n )\n },\n {\n type: 'longitudeFormat',\n template: createLowerFirstExpression(\n 'Enter a valid longitude for {{lowerFirst(#title)}} like -0.127758'\n )\n }\n ],\n advancedSettingsErrors: [\n {\n type: 'latitudeMin',\n template: createLowerFirstExpression(\n 'Latitude for {{lowerFirst(#title)}} must be between 49 and 60'\n )\n },\n {\n type: 'latitudeMax',\n template: createLowerFirstExpression(\n 'Latitude for {{lowerFirst(#title)}} must be between 49 and 60'\n )\n },\n {\n type: 'longitudeMin',\n template: createLowerFirstExpression(\n 'Longitude for {{lowerFirst(#title)}} must be between -9 and 2'\n )\n },\n {\n type: 'longitudeMax',\n template: createLowerFirstExpression(\n 'Longitude for {{lowerFirst(#title)}} must be between -9 and 2'\n )\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"],"mappings":"AAAA,SAASA,aAAa,QAAoC,oBAAoB;AAE9E,OAAOC,UAAU,MAAM,sBAAsB;AAE7C,SAASC,mBAAmB;AAC5B,SACEC,aAAa,EACbC,WAAW;AAEb,SACEC,uBAAuB,EACvBC,yBAAyB;AAE3B,SAASC,WAAW;AACpB,SAASC,0BAA0B;AAEnC,SAASC,eAAe;AASxB,SAASC,yBAAyB;;AAElC;AACA;AACA,MAAMC,iBAAiB,GAAG,CAAC,EAAC;;AAE5B,OAAO,MAAMC,YAAY,SAAST,aAAa,CAAC;EAM9CU,WAAWA,CACTC,GAA0B,EAC1BC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEC,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SAAS,CAACD,KAAK,CAAC;EACtC;;EAEA;AACF;AACA;EACEe,oBAAoBA,CAAA,EAA6B;IAC/C,OAAOrD,YAAY,CAACqD,oBAAoB,CAAC,CAAC;EAC5C;;EAEA;AACF;AACA;EACE,OAAOA,oBAAoBA,CAAA,EAA6B;IACtD,OAAO;MACLC,UAAU,EAAE,CACV;QAAE5B,IAAI,EAAE,UAAU;QAAE6B,QAAQ,EAAE1D,eAAe,CAACW;MAAS,CAAC,EACxD;QACEkB,IAAI,EAAE,gBAAgB;QACtB6B,QAAQ,EAAE3D,0BAA0B,CAClC,kEACF;MACF,CAAC,EACD;QACE8B,IAAI,EAAE,iBAAiB;QACvB6B,QAAQ,EAAE3D,0BAA0B,CAClC,mEACF;MACF,CAAC,CACF;MACD4D,sBAAsB,EAAE,CACtB;QACE9B,IAAI,EAAE,aAAa;QACnB6B,QAAQ,EAAE3D,0BAA0B,CAClC,+DACF;MACF,CAAC,EACD;QACE8B,IAAI,EAAE,aAAa;QACnB6B,QAAQ,EAAE3D,0BAA0B,CAClC,+DACF;MACF,CAAC,EACD;QACE8B,IAAI,EAAE,cAAc;QACpB6B,QAAQ,EAAE3D,0BAA0B,CAClC,+DACF;MACF,CAAC,EACD;QACE8B,IAAI,EAAE,cAAc;QACpB6B,QAAQ,EAAE3D,0BAA0B,CAClC,+DACF;MACF,CAAC;IAEL,CAAC;EACH;EAEA,OAAO2C,SAASA,CAACD,KAAkC,EAAyB;IAC1E,OACE9C,WAAW,CAAC8C,KAAK,CAAC,IAClB3C,WAAW,CAAC8D,QAAQ,CAACnB,KAAK,CAAC5B,QAAQ,CAAC,IACpCf,WAAW,CAAC8D,QAAQ,CAACnB,KAAK,CAACvB,SAAS,CAAC;EAEzC;AACF","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { type FormComponentsDef } from '@defra/forms-model';
2
- import { type LanguageMessages, type StringSchema } from 'joi';
2
+ import { type JoiExpression, type LanguageMessages, type StringSchema } from 'joi';
3
3
  import { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js';
4
4
  import { type ErrorMessageTemplateList, type FormPayload, type FormState, type FormStateValue, type FormSubmissionError, type FormSubmissionState } from '~/src/server/plugins/engine/types.js';
5
5
  interface LocationFieldOptions {
@@ -11,8 +11,8 @@ interface LocationFieldOptions {
11
11
  }
12
12
  interface ValidationConfig {
13
13
  pattern: RegExp;
14
- patternErrorMessage: string;
15
- requiredMessage?: string;
14
+ patternErrorMessage: JoiExpression;
15
+ requiredMessage?: JoiExpression;
16
16
  }
17
17
  /**
18
18
  * Abstract base class for location-based field components
@@ -25,7 +25,7 @@ export declare abstract class LocationFieldBase extends FormComponent {
25
25
  protected abstract getValidationConfig(): ValidationConfig;
26
26
  protected abstract getErrorTemplates(): {
27
27
  type: string;
28
- template: string;
28
+ template: JoiExpression;
29
29
  }[];
30
30
  constructor(def: FormComponentsDef, props: ConstructorParameters<typeof FormComponent>[1]);
31
31
  getFormValueFromState(state: FormSubmissionState): string | undefined;
@@ -2,6 +2,7 @@ import joi from 'joi';
2
2
  import { FormComponent, isFormValue } from "./FormComponent.js";
3
3
  import { addClassOptionIfNone } from "./helpers/index.js";
4
4
  import { messageTemplate } from "../pageControllers/validationOptions.js";
5
+ import { convertToLanguageMessages } from "../../../utils/type-utils.js";
5
6
  /**
6
7
  * Abstract base class for location-based field components
7
8
  */
@@ -17,11 +18,11 @@ export class LocationFieldBase extends FormComponent {
17
18
  addClassOptionIfNone(locationOptions, 'govuk-input--width-10');
18
19
  const config = this.getValidationConfig();
19
20
  const requiredMessage = config.requiredMessage ?? messageTemplate.required;
20
- const messages = {
21
+ const messages = convertToLanguageMessages({
21
22
  'any.required': requiredMessage,
22
23
  'string.empty': requiredMessage,
23
24
  'string.pattern.base': config.patternErrorMessage
24
- };
25
+ });
25
26
  let formSchema = joi.string().trim().label(this.label).required().pattern(config.pattern).messages(messages);
26
27
  if (locationOptions.required === false) {
27
28
  formSchema = formSchema.allow('');
@@ -1 +1 @@
1
- {"version":3,"file":"LocationFieldBase.js","names":["joi","FormComponent","isFormValue","addClassOptionIfNone","messageTemplate","LocationFieldBase","instructionText","constructor","def","props","options","locationOptions","config","getValidationConfig","requiredMessage","required","messages","patternErrorMessage","formSchema","string","trim","label","pattern","allow","customValidationMessage","message","messageKeys","reduce","acc","key","customValidationMessages","default","stateSchema","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","isText","getViewModel","payload","errors","viewModel","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 { 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 requiredMessage?: string\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 const requiredMessage =\n config.requiredMessage ?? (messageTemplate.required as string)\n\n const messages: LanguageMessages = {\n 'any.required': requiredMessage,\n 'string.empty': requiredMessage,\n 'string.pattern.base': config.patternErrorMessage\n }\n\n let formSchema = joi\n .string()\n .trim()\n .label(this.label)\n .required()\n .pattern(config.pattern)\n .messages(messages)\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 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: this.instructionText\n }\n }\n\n return viewModel\n }\n\n getAllPossibleErrors(): ErrorMessageTemplateList {\n const config = this.getValidationConfig()\n\n return {\n baseErrors: [\n {\n type: 'required',\n template:\n config.requiredMessage ?? (messageTemplate.required as string)\n },\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,eAAe;AAwBxB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AChBC,QAAQ,EACNpC,MAAM,CAACE,eAAe,IAAKV,eAAe,CAACW;MAC/C,CAAC,EACD,GAAG,IAAI,CAACkC,iBAAiB,CAAC,CAAC,CAC5B;MACDC,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOV,MAAMA,CAACH,KAAkC,EAAmB;IACjE,OAAOnC,WAAW,CAACmC,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,QAAQ;EACxD;AACF","ignoreList":[]}
1
+ {"version":3,"file":"LocationFieldBase.js","names":["joi","FormComponent","isFormValue","addClassOptionIfNone","messageTemplate","convertToLanguageMessages","LocationFieldBase","instructionText","constructor","def","props","options","locationOptions","config","getValidationConfig","requiredMessage","required","messages","patternErrorMessage","formSchema","string","trim","label","pattern","allow","customValidationMessage","message","messageKeys","reduce","acc","key","customValidationMessages","default","stateSchema","getFormValueFromState","state","name","getFormValue","value","isValue","undefined","isText","getViewModel","payload","errors","viewModel","getAllPossibleErrors","baseErrors","type","template","getErrorTemplates","advancedSettingsErrors"],"sources":["../../../../../src/server/plugins/engine/components/LocationFieldBase.ts"],"sourcesContent":["import { type FormComponentsDef } from '@defra/forms-model'\nimport joi, {\n type JoiExpression,\n type LanguageMessages,\n type StringSchema\n} 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 { 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\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: JoiExpression\n requiredMessage?: JoiExpression\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: JoiExpression\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 const requiredMessage =\n config.requiredMessage ?? (messageTemplate.required as string)\n\n const messages = convertToLanguageMessages({\n 'any.required': requiredMessage,\n 'string.empty': requiredMessage,\n 'string.pattern.base': config.patternErrorMessage\n })\n\n let formSchema = joi\n .string()\n .trim()\n .label(this.label)\n .required()\n .pattern(config.pattern)\n .messages(messages)\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 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: this.instructionText\n }\n }\n\n return viewModel\n }\n\n getAllPossibleErrors(): ErrorMessageTemplateList {\n const config = this.getValidationConfig()\n\n return {\n baseErrors: [\n {\n type: 'required',\n template:\n config.requiredMessage ?? (messageTemplate.required as string)\n },\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,MAIH,KAAK;AAEZ,SACEC,aAAa,EACbC,WAAW;AAEb,SAASC,oBAAoB;AAC7B,SAASC,eAAe;AASxB,SAASC,yBAAyB;AAgBlC;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;IACzC,MAAMC,eAAe,GACnBF,MAAM,CAACE,eAAe,IAAKX,eAAe,CAACY,QAAmB;IAEhE,MAAMC,QAAQ,GAAGZ,yBAAyB,CAAC;MACzC,cAAc,EAAEU,eAAe;MAC/B,cAAc,EAAEA,eAAe;MAC/B,qBAAqB,EAAEF,MAAM,CAACK;IAChC,CAAC,CAAC;IAEF,IAAIC,UAAU,GAAGnB,GAAG,CACjBoB,MAAM,CAAC,CAAC,CACRC,IAAI,CAAC,CAAC,CACNC,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC,CACjBN,QAAQ,CAAC,CAAC,CACVO,OAAO,CAACV,MAAM,CAACU,OAAO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AM,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,CAACrC,eAAe,EAAE;MACxB,OAAO;QACL,GAAGsC,SAAS;QACZtC,eAAe,EAAE,IAAI,CAACA;MACxB,CAAC;IACH;IAEA,OAAOsC,SAAS;EAClB;EAEAC,oBAAoBA,CAAA,EAA6B;IAC/C,MAAMjC,MAAM,GAAG,IAAI,CAACC,mBAAmB,CAAC,CAAC;IAEzC,OAAO;MACLiC,UAAU,EAAE,CACV;QACEC,IAAI,EAAE,UAAU;QAChBC,QAAQ,EACNpC,MAAM,CAACE,eAAe,IAAKX,eAAe,CAACY;MAC/C,CAAC,EACD,GAAG,IAAI,CAACkC,iBAAiB,CAAC,CAAC,CAC5B;MACDC,sBAAsB,EAAE;IAC1B,CAAC;EACH;EAEA,OAAOV,MAAMA,CAACH,KAAkC,EAAmB;IACjE,OAAOpC,WAAW,CAACoC,KAAK,CAAC,IAAI,OAAOA,KAAK,KAAK,QAAQ;EACxD;AACF","ignoreList":[]}
@@ -3,9 +3,11 @@ import { ComponentBase } from '~/src/server/plugins/engine/components/ComponentB
3
3
  export declare class Markdown extends ComponentBase {
4
4
  options: MarkdownComponent['options'];
5
5
  content: MarkdownComponent['content'];
6
+ headerStartLevel: number;
6
7
  constructor(def: MarkdownComponent, props: ConstructorParameters<typeof ComponentBase>[1]);
7
8
  getViewModel(): {
8
9
  content: string;
10
+ headerStartLevel: number;
9
11
  label?: import("./types.js").Label;
10
12
  type?: string;
11
13
  id?: string;
@@ -1,6 +1,7 @@
1
1
  import { ComponentBase } from "./ComponentBase.js";
2
2
  export class Markdown extends ComponentBase {
3
3
  content;
4
+ headerStartLevel;
4
5
  constructor(def, props) {
5
6
  super(def, props);
6
7
  const {
@@ -9,6 +10,7 @@ export class Markdown extends ComponentBase {
9
10
  } = def;
10
11
  this.content = content;
11
12
  this.options = options;
13
+ this.headerStartLevel = 2;
12
14
  }
13
15
  getViewModel() {
14
16
  const {
@@ -17,7 +19,8 @@ export class Markdown extends ComponentBase {
17
19
  } = this;
18
20
  return {
19
21
  ...viewModel,
20
- content
22
+ content,
23
+ headerStartLevel: this.headerStartLevel
21
24
  };
22
25
  }
23
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Markdown.js","names":["ComponentBase","Markdown","content","constructor","def","props","options","getViewModel","viewModel"],"sources":["../../../../../src/server/plugins/engine/components/Markdown.ts"],"sourcesContent":["import { type MarkdownComponent } from '@defra/forms-model'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\n\nexport class Markdown extends ComponentBase {\n declare options: MarkdownComponent['options']\n content: MarkdownComponent['content']\n\n constructor(\n def: MarkdownComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { content, options } = def\n\n this.content = content\n this.options = options\n }\n\n getViewModel() {\n const { content, viewModel } = this\n\n return {\n ...viewModel,\n content\n }\n }\n}\n"],"mappings":"AAEA,SAASA,aAAa;AAEtB,OAAO,MAAMC,QAAQ,SAASD,aAAa,CAAC;EAE1CE,OAAO;EAEPC,WAAWA,CACTC,GAAsB,EACtBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEH,OAAO;MAAEI;IAAQ,CAAC,GAAGF,GAAG;IAEhC,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACI,OAAO,GAAGA,OAAO;EACxB;EAEAC,YAAYA,CAAA,EAAG;IACb,MAAM;MAAEL,OAAO;MAAEM;IAAU,CAAC,GAAG,IAAI;IAEnC,OAAO;MACL,GAAGA,SAAS;MACZN;IACF,CAAC;EACH;AACF","ignoreList":[]}
1
+ {"version":3,"file":"Markdown.js","names":["ComponentBase","Markdown","content","headerStartLevel","constructor","def","props","options","getViewModel","viewModel"],"sources":["../../../../../src/server/plugins/engine/components/Markdown.ts"],"sourcesContent":["import { type MarkdownComponent } from '@defra/forms-model'\n\nimport { ComponentBase } from '~/src/server/plugins/engine/components/ComponentBase.js'\n\nexport class Markdown extends ComponentBase {\n declare options: MarkdownComponent['options']\n content: MarkdownComponent['content']\n headerStartLevel: number\n\n constructor(\n def: MarkdownComponent,\n props: ConstructorParameters<typeof ComponentBase>[1]\n ) {\n super(def, props)\n\n const { content, options } = def\n\n this.content = content\n this.options = options\n this.headerStartLevel = 2\n }\n\n getViewModel() {\n const { content, viewModel } = this\n\n return {\n ...viewModel,\n content,\n headerStartLevel: this.headerStartLevel\n }\n }\n}\n"],"mappings":"AAEA,SAASA,aAAa;AAEtB,OAAO,MAAMC,QAAQ,SAASD,aAAa,CAAC;EAE1CE,OAAO;EACPC,gBAAgB;EAEhBC,WAAWA,CACTC,GAAsB,EACtBC,KAAqD,EACrD;IACA,KAAK,CAACD,GAAG,EAAEC,KAAK,CAAC;IAEjB,MAAM;MAAEJ,OAAO;MAAEK;IAAQ,CAAC,GAAGF,GAAG;IAEhC,IAAI,CAACH,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACK,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACJ,gBAAgB,GAAG,CAAC;EAC3B;EAEAK,YAAYA,CAAA,EAAG;IACb,MAAM;MAAEN,OAAO;MAAEO;IAAU,CAAC,GAAG,IAAI;IAEnC,OAAO;MACL,GAAGA,SAAS;MACZP,OAAO;MACPC,gBAAgB,EAAE,IAAI,CAACA;IACzB,CAAC;EACH;AACF","ignoreList":[]}
@@ -4,12 +4,12 @@ export declare class NationalGridFieldNumberField extends LocationFieldBase {
4
4
  options: NationalGridFieldNumberFieldComponent['options'];
5
5
  protected getValidationConfig(): {
6
6
  pattern: RegExp;
7
- patternErrorMessage: string;
8
- requiredMessage: string;
7
+ patternErrorMessage: import("joi").JoiExpression;
8
+ requiredMessage: import("joi").JoiExpression;
9
9
  };
10
10
  protected getErrorTemplates(): {
11
11
  type: string;
12
- template: string;
12
+ template: import("joi").JoiExpression;
13
13
  }[];
14
14
  /**
15
15
  * Static version of getAllPossibleErrors that doesn't require a component instance.
@@ -1,20 +1,22 @@
1
1
  import { LocationFieldBase } from "./LocationFieldBase.js";
2
+ import { createLowerFirstExpression } from "./helpers/index.js";
2
3
  export class NationalGridFieldNumberField extends LocationFieldBase {
3
4
  getValidationConfig() {
4
5
  // Regex for OS national grid field references (NGFR)
5
6
  // Validates specific valid OS grid letter combinations with:
6
7
  // - 2 letters & 8 digits in 2 blocks of 4 e.g. ST 6789 6789
7
8
  const pattern = /^((([sS]|[nN])[a-hA-Hj-zJ-Z])|(([tT]|[oO])[abfglmqrvwABFGLMQRVW])|([hH][l-zL-Z])|([jJ][lmqrvwLMQRVW]))\s?([0-9]{4})\s?([0-9]{4})$/;
9
+ const patternTemplate = 'Enter a valid National Grid field number for {{lowerFirst(#title)}} like NG 1234 5678';
8
10
  return {
9
11
  pattern,
10
- patternErrorMessage: `Enter a valid National Grid field number for {{#title}} like NG 1234 5678`,
11
- requiredMessage: 'Enter {{#title}}'
12
+ patternErrorMessage: createLowerFirstExpression(patternTemplate),
13
+ requiredMessage: createLowerFirstExpression('Enter {{lowerFirst(#title)}}')
12
14
  };
13
15
  }
14
16
  getErrorTemplates() {
15
17
  return [{
16
18
  type: 'pattern',
17
- template: 'Enter a valid National Grid field number for {{#title}} like NG 1234 5678'
19
+ template: createLowerFirstExpression('Enter a valid National Grid field number for {{lowerFirst(#title)}} like NG 1234 5678')
18
20
  }];
19
21
  }
20
22
 
@@ -1 +1 @@
1
- {"version":3,"file":"NationalGridFieldNumberField.js","names":["LocationFieldBase","NationalGridFieldNumberField","getValidationConfig","pattern","patternErrorMessage","requiredMessage","getErrorTemplates","type","template","getAllPossibleErrors","instance","Object","create","prototype"],"sources":["../../../../../src/server/plugins/engine/components/NationalGridFieldNumberField.ts"],"sourcesContent":["import { type NationalGridFieldNumberFieldComponent } from '@defra/forms-model'\n\nimport { LocationFieldBase } from '~/src/server/plugins/engine/components/LocationFieldBase.js'\n\nexport class NationalGridFieldNumberField extends LocationFieldBase {\n declare options: NationalGridFieldNumberFieldComponent['options']\n\n protected getValidationConfig() {\n // Regex for OS national grid field references (NGFR)\n // Validates specific valid OS grid letter combinations with:\n // - 2 letters & 8 digits in 2 blocks of 4 e.g. ST 6789 6789\n const pattern =\n /^((([sS]|[nN])[a-hA-Hj-zJ-Z])|(([tT]|[oO])[abfglmqrvwABFGLMQRVW])|([hH][l-zL-Z])|([jJ][lmqrvwLMQRVW]))\\s?([0-9]{4})\\s?([0-9]{4})$/\n\n return {\n pattern,\n patternErrorMessage: `Enter a valid National Grid field number for {{#title}} like NG 1234 5678`,\n requiredMessage: 'Enter {{#title}}'\n }\n }\n\n protected getErrorTemplates() {\n return [\n {\n type: 'pattern',\n template:\n 'Enter a valid National Grid field number for {{#title}} like NG 1234 5678'\n }\n ]\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors() {\n const instance = Object.create(\n NationalGridFieldNumberField.prototype\n ) as NationalGridFieldNumberField\n return instance.getAllPossibleErrors()\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB;AAE1B,OAAO,MAAMC,4BAA4B,SAASD,iBAAiB,CAAC;EAGxDE,mBAAmBA,CAAA,EAAG;IAC9B;IACA;IACA;IACA,MAAMC,OAAO,GACX,mIAAmI;IAErI,OAAO;MACLA,OAAO;MACPC,mBAAmB,EAAE,2EAA2E;MAChGC,eAAe,EAAE;IACnB,CAAC;EACH;EAEUC,iBAAiBA,CAAA,EAAG;IAC5B,OAAO,CACL;MACEC,IAAI,EAAE,SAAS;MACfC,QAAQ,EACN;IACJ,CAAC,CACF;EACH;;EAEA;AACF;AACA;EACE,OAAOC,oBAAoBA,CAAA,EAAG;IAC5B,MAAMC,QAAQ,GAAGC,MAAM,CAACC,MAAM,CAC5BX,4BAA4B,CAACY,SAC/B,CAAiC;IACjC,OAAOH,QAAQ,CAACD,oBAAoB,CAAC,CAAC;EACxC;AACF","ignoreList":[]}
1
+ {"version":3,"file":"NationalGridFieldNumberField.js","names":["LocationFieldBase","createLowerFirstExpression","NationalGridFieldNumberField","getValidationConfig","pattern","patternTemplate","patternErrorMessage","requiredMessage","getErrorTemplates","type","template","getAllPossibleErrors","instance","Object","create","prototype"],"sources":["../../../../../src/server/plugins/engine/components/NationalGridFieldNumberField.ts"],"sourcesContent":["import { type NationalGridFieldNumberFieldComponent } from '@defra/forms-model'\n\nimport { LocationFieldBase } from '~/src/server/plugins/engine/components/LocationFieldBase.js'\nimport { createLowerFirstExpression } from '~/src/server/plugins/engine/components/helpers/index.js'\n\nexport class NationalGridFieldNumberField extends LocationFieldBase {\n declare options: NationalGridFieldNumberFieldComponent['options']\n\n protected getValidationConfig() {\n // Regex for OS national grid field references (NGFR)\n // Validates specific valid OS grid letter combinations with:\n // - 2 letters & 8 digits in 2 blocks of 4 e.g. ST 6789 6789\n const pattern =\n /^((([sS]|[nN])[a-hA-Hj-zJ-Z])|(([tT]|[oO])[abfglmqrvwABFGLMQRVW])|([hH][l-zL-Z])|([jJ][lmqrvwLMQRVW]))\\s?([0-9]{4})\\s?([0-9]{4})$/\n\n const patternTemplate =\n 'Enter a valid National Grid field number for {{lowerFirst(#title)}} like NG 1234 5678'\n\n return {\n pattern,\n patternErrorMessage: createLowerFirstExpression(patternTemplate),\n requiredMessage: createLowerFirstExpression(\n 'Enter {{lowerFirst(#title)}}'\n )\n }\n }\n\n protected getErrorTemplates() {\n return [\n {\n type: 'pattern',\n template: createLowerFirstExpression(\n 'Enter a valid National Grid field number for {{lowerFirst(#title)}} like NG 1234 5678'\n )\n }\n ]\n }\n\n /**\n * Static version of getAllPossibleErrors that doesn't require a component instance.\n */\n static getAllPossibleErrors() {\n const instance = Object.create(\n NationalGridFieldNumberField.prototype\n ) as NationalGridFieldNumberField\n return instance.getAllPossibleErrors()\n }\n}\n"],"mappings":"AAEA,SAASA,iBAAiB;AAC1B,SAASC,0BAA0B;AAEnC,OAAO,MAAMC,4BAA4B,SAASF,iBAAiB,CAAC;EAGxDG,mBAAmBA,CAAA,EAAG;IAC9B;IACA;IACA;IACA,MAAMC,OAAO,GACX,mIAAmI;IAErI,MAAMC,eAAe,GACnB,uFAAuF;IAEzF,OAAO;MACLD,OAAO;MACPE,mBAAmB,EAAEL,0BAA0B,CAACI,eAAe,CAAC;MAChEE,eAAe,EAAEN,0BAA0B,CACzC,8BACF;IACF,CAAC;EACH;EAEUO,iBAAiBA,CAAA,EAAG;IAC5B,OAAO,CACL;MACEC,IAAI,EAAE,SAAS;MACfC,QAAQ,EAAET,0BAA0B,CAClC,uFACF;IACF,CAAC,CACF;EACH;;EAEA;AACF;AACA;EACE,OAAOU,oBAAoBA,CAAA,EAAG;IAC5B,MAAMC,QAAQ,GAAGC,MAAM,CAACC,MAAM,CAC5BZ,4BAA4B,CAACa,SAC/B,CAAiC;IACjC,OAAOH,QAAQ,CAACD,oBAAoB,CAAC,CAAC;EACxC;AACF","ignoreList":[]}
@@ -4,12 +4,12 @@ export declare class OsGridRefField extends LocationFieldBase {
4
4
  options: OsGridRefFieldComponent['options'];
5
5
  protected getValidationConfig(): {
6
6
  pattern: RegExp;
7
- patternErrorMessage: string;
8
- requiredMessage: string;
7
+ patternErrorMessage: import("joi").JoiExpression;
8
+ requiredMessage: import("joi").JoiExpression;
9
9
  };
10
10
  protected getErrorTemplates(): {
11
11
  type: string;
12
- template: string;
12
+ template: import("joi").JoiExpression;
13
13
  }[];
14
14
  /**
15
15
  * Static version of getAllPossibleErrors that doesn't require a component instance.
@@ -1,4 +1,5 @@
1
1
  import { LocationFieldBase } from "./LocationFieldBase.js";
2
+ import { createLowerFirstExpression } from "./helpers/index.js";
2
3
  export class OsGridRefField extends LocationFieldBase {
3
4
  getValidationConfig() {
4
5
  // Regex for OS national grid references (NGR)
@@ -8,16 +9,17 @@ export class OsGridRefField extends LocationFieldBase {
8
9
  // - 2 letters & 10 digits in 2 blocks of 5 e.g. SO 12345 12345
9
10
  // Optional spaces between each block
10
11
  const pattern = /^((([sS]|[nN])[a-hA-Hj-zJ-Z])|(([tT]|[oO])[abfglmqrvwABFGLMQRVW])|([hH][l-zL-Z])|([jJ][lmqrvwLMQRVW]))\s?(([0-9]{3})\s?([0-9]{3})|([0-9]{4})\s?([0-9]{4})|([0-9]{5})\s?([0-9]{5}))$/;
12
+ const patternTemplate = 'Enter a valid OS grid reference for {{lowerFirst(#title)}} like TQ123456';
11
13
  return {
12
14
  pattern,
13
- patternErrorMessage: `Enter a valid OS grid reference for {{#title}} like TQ123456`,
14
- requiredMessage: 'Enter {{#title}}'
15
+ patternErrorMessage: createLowerFirstExpression(patternTemplate),
16
+ requiredMessage: createLowerFirstExpression('Enter {{lowerFirst(#title)}}')
15
17
  };
16
18
  }
17
19
  getErrorTemplates() {
18
20
  return [{
19
21
  type: 'pattern',
20
- template: 'Enter a valid OS grid reference for {{#title}} like TQ123456'
22
+ template: createLowerFirstExpression('Enter a valid OS grid reference for {{lowerFirst(#title)}} like TQ123456')
21
23
  }];
22
24
  }
23
25