@planning-inspectorate/dynamic-forms 3.8.1 → 3.8.3

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/move-types.js ADDED
@@ -0,0 +1,14 @@
1
+ import { copyFile } from 'node:fs/promises';
2
+ import path from 'path';
3
+
4
+ async function copyAndOverwrite(src, dest) {
5
+ await copyFile(src, dest);
6
+ console.log(`Copied ${src} to ${dest}`);
7
+ }
8
+
9
+ const srcDir = path.join(import.meta.dirname, 'src', 'questions');
10
+ const typesDir = path.join(import.meta.dirname, 'types', 'src', 'questions');
11
+
12
+ // copy some of the type definition files to the types output that are not automatically included
13
+ copyAndOverwrite(path.join(srcDir, 'question-props.d.ts'), path.join(typesDir, 'question-props.d.ts'));
14
+ copyAndOverwrite(path.join(srcDir, 'question-types.d.ts'), path.join(typesDir, 'question-types.d.ts'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planning-inspectorate/dynamic-forms",
3
- "version": "3.8.1",
3
+ "version": "3.8.3",
4
4
  "description": "This package is for building GDS forms using a configuration-based approach.",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  "lint": "npx eslint .",
18
18
  "format": "prettier --write .",
19
19
  "format-check": "prettier --check .",
20
- "generate-types": "npx tsc --project tsconfig.json",
20
+ "generate-types": "npx tsc --project tsconfig.json && node move-types.js",
21
21
  "prepare": "node .husky/install.mjs",
22
22
  "test": "node --test",
23
23
  "test-coverage": "node --test --experimental-test-coverage"
@@ -30,7 +30,7 @@
30
30
  "nunjucks": "^3.2.4"
31
31
  },
32
32
  "imports": {
33
- "#question-types": "./src/questions/question-types.ts",
33
+ "#question-types": "./src/questions/question-types.d.ts",
34
34
  "#test/*": "./test/*",
35
35
  "#base-validator": "./src/validator/base-validator.js",
36
36
  "#journey": "./src/journey/journey.js",
package/src/controller.js CHANGED
@@ -53,7 +53,7 @@ function buildSectionViewModel(name, status = '') {
53
53
  * build a view model for a row in the journey overview
54
54
  * @param {string} key
55
55
  * @param {string} value
56
- * @param {ActionView|ActionView[]} action
56
+ * @param {ActionView|ActionView[]} [action]
57
57
  * @returns {RowView} a representation of a row
58
58
  */
59
59
  function buildSectionRowViewModel(key, value, action) {
@@ -64,9 +64,7 @@ function buildSectionRowViewModel(key, value, action) {
64
64
  value: {
65
65
  html: value
66
66
  },
67
- actions: {
68
- items: toArray(action)
69
- }
67
+ actions: action ? { items: toArray(action) } : undefined
70
68
  };
71
69
  }
72
70
 
@@ -299,6 +299,56 @@ describe('dynamic-form/controller', () => {
299
299
  assert.strictEqual(args[0], mockJourney.sections[0].segment);
300
300
  assert.strictEqual(args[2], expectedAnswer.value);
301
301
  });
302
+ it('should format an undefined action as undefined', async () => {
303
+ const mockFn = res.render.mock;
304
+ mockFn.resetCalls();
305
+ mockJourney.sections[0].questions[0].formatAnswerForSummary.mock.mockImplementation(() => [
306
+ {
307
+ key: 'Title 1a',
308
+ value: mockAnswer,
309
+ action: undefined
310
+ }
311
+ ]);
312
+ res.locals.journeyResponse.referenceId = mockRef;
313
+ const appeal = { a: 1, caseReference: 2 };
314
+
315
+ const pageCaption = `Appeal ${appeal.caseReference}`;
316
+ await list(req, res, pageCaption, { appeal });
317
+
318
+ const renderCall = mockFn.calls[0].arguments[1];
319
+ const firstRowActions = renderCall.summaryListData.sections[0].list.rows[0].actions;
320
+ assert.strictEqual(firstRowActions, undefined);
321
+ });
322
+
323
+ it('should format a single action object as an array in the actions property', async () => {
324
+ const mockFn = res.render.mock;
325
+ mockFn.resetCalls();
326
+ mockJourney.sections[0].questions[0].formatAnswerForSummary.mock.mockImplementation(() => [
327
+ {
328
+ key: 'Title 1a',
329
+ value: mockAnswer,
330
+ action: {
331
+ href: '/manage-appeals/questionnaire/123456/segment-1/title-1a',
332
+ text: 'Answer',
333
+ visuallyHiddenText: 'Answer'
334
+ }
335
+ }
336
+ ]);
337
+ res.locals.journeyResponse.referenceId = mockRef;
338
+
339
+ await list(req, res);
340
+
341
+ const renderCall = mockFn.calls[0].arguments[1];
342
+ const rowActions = renderCall.summaryListData.sections[0].list.rows[0].actions;
343
+ assert.ok(rowActions);
344
+ assert.ok(Array.isArray(rowActions.items));
345
+ assert.strictEqual(rowActions.items.length, 1);
346
+ assert.deepStrictEqual(rowActions.items[0], {
347
+ href: '/manage-appeals/questionnaire/123456/segment-1/title-1a',
348
+ text: 'Answer',
349
+ visuallyHiddenText: 'Answer'
350
+ });
351
+ });
302
352
  });
303
353
 
304
354
  describe('question', () => {
package/src/index.js CHANGED
@@ -46,8 +46,8 @@ export { createQuestions } from './questions/create-questions.js';
46
46
  export * from './questions/options-question.js';
47
47
  export { questionClasses } from './questions/questions.js';
48
48
 
49
- export * from './questions/question-props.ts';
50
- export * from './questions/question-types.ts';
49
+ export * from './questions/question-props.js';
50
+ export * from './questions/question-types.js';
51
51
 
52
52
  // Section
53
53
  export { Section } from './section.js';
@@ -1,4 +1,4 @@
1
- import type { QuestionParameters } from '#question-types';
1
+ import type { QuestionParameters } from '#src/questions/question-types.d.ts';
2
2
 
3
3
  type QuestionTypes =
4
4
  | 'boolean'
@@ -0,0 +1 @@
1
+ // empty source file to go with .d.ts file
@@ -0,0 +1 @@
1
+ // empty source file to go with .d.ts file
@@ -31,9 +31,8 @@ export const postcodeMinLength = 5;
31
31
  export default class AddressValidator extends BaseValidator {
32
32
  /**
33
33
  * creates an instance of an AddressValidator
34
- * @param {Object} opts
35
- * @param {boolean} [opts.required]
36
- * @param {{[key: string]: boolean}} [opts.requiredFields]
34
+ * @param {Object} [opts]
35
+ * @param {{addressLine1: boolean, addressLine2: boolean, townCity: boolean, county: boolean, postcode: boolean}} [opts.requiredFields]
37
36
  */
38
37
  constructor(opts) {
39
38
  super();
@@ -4,19 +4,19 @@ import BaseValidator from './base-validator.js';
4
4
  /**
5
5
  * @typedef {Object} MinLength
6
6
  * @property {Number} minLength
7
- * @property {String} minLengthMessage
7
+ * @property {String} [minLengthMessage]
8
8
  */
9
9
 
10
10
  /**
11
11
  * @typedef {Object} MaxLength
12
12
  * @property {Number} maxLength
13
- * @property {String} maxLengthMessage
13
+ * @property {String} [maxLengthMessage]
14
14
  */
15
15
 
16
16
  /**
17
17
  * @typedef {Object} Regex
18
18
  * @property {String | RegExp} regex
19
- * @property {String} regexMessage
19
+ * @property {String} [regexMessage]
20
20
  */
21
21
 
22
22
  export default class StringValidator extends BaseValidator {
package/tsconfig.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "target": "esnext",
21
21
  "skipLibCheck": true,
22
22
  "paths": {
23
- "#question-types": ["./src/questions/question-types.ts"],
23
+ "#question-types": ["./src/questions/question-types.d.ts"],
24
24
  "#src/*": ["./src/*"],
25
25
  "#test/*": ["./test/*"],
26
26
  "#question": ["./src/questions/question.js"],
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=move-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move-types.d.ts","sourceRoot":"","sources":["../move-types.js"],"names":[],"mappings":""}
@@ -4,7 +4,11 @@ export default class AddressQuestion extends Question {
4
4
  */
5
5
  constructor(params: import("#question-types").QuestionParameters);
6
6
  requiredFields: {
7
- [key: string]: boolean;
7
+ addressLine1: boolean;
8
+ addressLine2: boolean;
9
+ townCity: boolean;
10
+ county: boolean;
11
+ postcode: boolean;
8
12
  } | undefined;
9
13
  addressLabels: {
10
14
  addressLine1: string;
@@ -1 +1 @@
1
- {"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/address/question.js"],"names":[],"mappings":"AAOA;IACC;;OAEG;IACH,oBAFW,OAAO,iBAAiB,EAAE,kBAAkB,EAqBtD;IAXE;;kBAA8C;IAIhD;;;;;;MAMC;IAGF;;;OAGG;IACH,4BAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,GAAC,GAAC,MAAM,CAqBpB;IAqCD;;;OAGG;IACH;;eAUC;IAuBD,kEAMC;CACD;yBAxIwB,WAAW"}
1
+ {"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/address/question.js"],"names":[],"mappings":"AAOA;IACC;;OAEG;IACH,oBAFW,OAAO,iBAAiB,EAAE,kBAAkB,EAqBtD;IAXE;;;;;;kBAA8C;IAIhD;;;;;;MAMC;IAGF;;;OAGG;IACH,4BAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,GAAC,GAAC,MAAM,CAqBpB;IAqCD;;;OAGG;IACH;;eAUC;IAuBD,kEAMC;CACD;yBAxIwB,WAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller.js"],"names":[],"mappings":"AAwEA;;;GAGG;AACH,qCAHW,MAAM,OAKhB;AAED;;;;;GAKG;AACH,sDAHW,MAAM,YACN,MAAM,gBA8DhB;AAED;;;;GAIG;AACH,2DA0CC;AAED;;;;;;;;;;GAUG;AAEH;;GAEG;AAEH;;;;GAIG;AACH,oCAJW,UAAU,gCACV,OAAO,OAuFjB;sBAtSY,OAAO,sBAAsB,EAAE,OAAO;uBACtC,OAAO,yBAAyB,EAAE,QAAQ;;;aAMzC,MAAM;YACN,MAAM;UAEjB;QAAiC,IAAI,EAA1B,KAAK,CAAE,OAAO,CAAC;KAC5B;;;SAIa;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;WAChB;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;;eAC1B,UAAU,EAAE;;;;UAKrB,MAAM;UACN,MAAM;;;;;;eA0KN,MAAM;iBACN,MAAM;sBACN,OAAO;;;;;;;yBAOR,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC"}
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller.js"],"names":[],"mappings":"AAsEA;;;GAGG;AACH,qCAHW,MAAM,OAKhB;AAED;;;;;GAKG;AACH,sDAHW,MAAM,YACN,MAAM,gBA8DhB;AAED;;;;GAIG;AACH,2DA0CC;AAED;;;;;;;;;;GAUG;AAEH;;GAEG;AAEH;;;;GAIG;AACH,oCAJW,UAAU,gCACV,OAAO,OAuFjB;sBApSY,OAAO,sBAAsB,EAAE,OAAO;uBACtC,OAAO,yBAAyB,EAAE,QAAQ;;;aAMzC,MAAM;YACN,MAAM;UAEjB;QAAiC,IAAI,EAA1B,KAAK,CAAE,OAAO,CAAC;KAC5B;;;SAIa;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;WAChB;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;;eAC1B,UAAU,EAAE;;;;UAKrB,MAAM;UACN,MAAM;;;;;;eAwKN,MAAM;iBACN,MAAM;sBACN,OAAO;;;;;;;yBAOR,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC"}
@@ -23,8 +23,8 @@ export * from "./lib/utils.js";
23
23
  export * from "./middleware/build-get-journey.js";
24
24
  export * from "./middleware/redirect-to-unanswered-question.js";
25
25
  export * from "./questions/options-question.js";
26
- export * from "./questions/question-props.ts";
27
- export * from "./questions/question-types.ts";
26
+ export * from "./questions/question-props.js";
27
+ export * from "./questions/question-types.js";
28
28
  export * from "./validator/address-validator.js";
29
29
  export * from "./validator/base-validator.js";
30
30
  export * from "./validator/conditional-required-validator.js";
@@ -1,113 +1,173 @@
1
- import type { QuestionParameters } from '#question-types';
2
- type QuestionTypes = 'boolean' | 'checkbox' | 'date' | 'date-period' | 'date-time' | 'email' | 'manage-list' | 'multi-field-input' | 'number' | 'radio' | 'select' | 'single-line-input' | 'site-address' | 'text-entry' | 'text-entry-redact' | 'unit-option';
1
+ import type { QuestionParameters } from '#src/questions/question-types.d.ts';
2
+
3
+ type QuestionTypes =
4
+ | 'boolean'
5
+ | 'checkbox'
6
+ | 'date'
7
+ | 'date-period'
8
+ | 'date-time'
9
+ | 'email'
10
+ | 'manage-list'
11
+ | 'multi-field-input'
12
+ | 'number'
13
+ | 'radio'
14
+ | 'select'
15
+ | 'single-line-input'
16
+ | 'site-address'
17
+ | 'text-entry'
18
+ | 'text-entry-redact'
19
+ | 'unit-option';
20
+
3
21
  type CommonQuestionProps = Omit<QuestionParameters, 'viewFolder'> & {
4
- type: QuestionTypes;
5
- };
6
- type Option = {
7
- text: string;
8
- value: string;
9
- hint?: object;
10
- checked?: boolean | undefined;
11
- attributes?: Record<string, string>;
12
- behaviour?: 'exclusive';
13
- conditional?: {
14
- question: string;
15
- type: string;
16
- fieldName: string;
17
- inputClasses?: string;
18
- html?: string;
19
- value?: unknown;
20
- label?: string;
21
- hint?: string;
22
- };
23
- conditionalText?: {
24
- html: string;
25
- };
26
- } | {
27
- divider?: string;
28
- };
22
+ type: QuestionTypes;
23
+ };
24
+
25
+ type Option =
26
+ | {
27
+ text: string;
28
+ value: string;
29
+ hint?: object;
30
+ checked?: boolean | undefined;
31
+ attributes?: Record<string, string>;
32
+ behaviour?: 'exclusive';
33
+ conditional?: {
34
+ question: string;
35
+ type: string;
36
+ fieldName: string;
37
+ inputClasses?: string;
38
+ html?: string;
39
+ value?: unknown;
40
+ label?: string;
41
+ hint?: string;
42
+ };
43
+ conditionalText?: {
44
+ html: string;
45
+ };
46
+ }
47
+ | { divider?: string };
48
+
29
49
  interface InputField {
30
- fieldName: string;
31
- label: string;
32
- formatJoinString?: string;
33
- hint?: string;
50
+ fieldName: string;
51
+ label: string;
52
+ formatJoinString?: string; // optional property, used by formatAnswerForSummary (eg task list display), effective default to line break
53
+ hint?: string;
34
54
  }
55
+
56
+ /*
57
+ * UnitOptions are the options displayed in the radio format - in this case the value
58
+ * represents the unit.
59
+ * Conditionals must be used to capture the relevant quantity.
60
+ * Each conditional must have a fieldName which uses the conditionalFieldName from the
61
+ * UnitOptionEntryQuestion object as a base, followed by an underscore and unit reference
62
+ * eg 'siteAreaSquareMetres_hectares' - this is required for validation and saving to the DB
63
+ */
35
64
  interface UnitOption {
36
- text: string;
37
- value: string;
38
- hint?: object;
39
- checked?: boolean | undefined;
40
- attributes?: Record<string, string>;
41
- behaviour?: 'exclusive';
42
- conditional: {
43
- fieldName: string;
44
- suffix: string;
45
- value?: unknown;
46
- label?: string;
47
- hint?: string;
48
- conversionFactor?: number;
49
- };
65
+ text: string;
66
+ value: string;
67
+ hint?: object;
68
+ checked?: boolean | undefined;
69
+ attributes?: Record<string, string>;
70
+ behaviour?: 'exclusive';
71
+ conditional: {
72
+ fieldName: string;
73
+ suffix: string;
74
+ value?: unknown;
75
+ label?: string;
76
+ hint?: string;
77
+ conversionFactor?: number;
78
+ };
50
79
  }
80
+
51
81
  type BooleanQuestionProps = CommonQuestionProps & {
52
- type: 'boolean';
53
- options?: Option[];
54
- interfaceType?: 'checkbox' | 'radio';
82
+ type: 'boolean';
83
+ options?: Option[];
84
+ interfaceType?: 'checkbox' | 'radio';
55
85
  };
86
+
56
87
  type CheckboxQuestionProps = CommonQuestionProps & {
57
- type: 'checkbox';
58
- options: Option[];
88
+ type: 'checkbox';
89
+ options: Option[];
59
90
  };
91
+
60
92
  type DateQuestionProps = CommonQuestionProps & {
61
- type: 'date';
93
+ type: 'date';
62
94
  };
95
+
63
96
  type DatePeriodQuestionProps = CommonQuestionProps & {
64
- type: 'date-period';
97
+ type: 'date-period';
65
98
  };
99
+
66
100
  type DateTimeQuestionProps = CommonQuestionProps & {
67
- type: 'date-time';
101
+ type: 'date-time';
68
102
  };
103
+
69
104
  type ManageListQuestionProps = CommonQuestionProps & {
70
- type: 'manage-list';
105
+ type: 'manage-list';
71
106
  };
107
+
72
108
  type EmailQuestionProps = CommonQuestionProps & {
73
- type: 'email';
109
+ type: 'email';
74
110
  };
111
+
75
112
  type MultiFieldInputQuestionProps = CommonQuestionProps & {
76
- type: 'multi-field-input';
77
- inputAttributes?: Record<string, string>;
78
- inputFields: InputField[];
79
- formatType?: 'contactDetails' | 'standard';
113
+ type: 'multi-field-input';
114
+ inputAttributes?: Record<string, string>;
115
+ inputFields: InputField[];
116
+ formatType?: 'contactDetails' | 'standard';
80
117
  };
118
+
81
119
  type NumberEntryQuestionProps = CommonQuestionProps & {
82
- type: 'number';
83
- suffix?: string;
120
+ type: 'number';
121
+ suffix?: string;
84
122
  };
123
+
85
124
  type RadioQuestionProps = CommonQuestionProps & {
86
- type: 'radio';
87
- options: Option[];
125
+ type: 'radio';
126
+ options: Option[];
88
127
  };
128
+
89
129
  type SelectQuestionProps = CommonQuestionProps & {
90
- type: 'select';
91
- options: Option[];
130
+ type: 'select';
131
+ options: Option[];
92
132
  };
133
+
93
134
  type SingleLineInputQuestionProps = CommonQuestionProps & {
94
- type: 'single-line-input';
95
- inputAttributes?: Record<string, string>;
135
+ type: 'single-line-input';
136
+ inputAttributes?: Record<string, string>;
96
137
  };
138
+
97
139
  type SiteAddressQuestionProps = CommonQuestionProps & {
98
- type: 'site-address';
140
+ type: 'site-address';
99
141
  };
142
+
100
143
  type TextEntryQuestionProps = CommonQuestionProps & {
101
- type: 'text-entry';
144
+ type: 'text-entry';
102
145
  };
146
+
103
147
  type TextEntryRedactQuestionProps = CommonQuestionProps & {
104
- type: 'text-entry-redact';
148
+ type: 'text-entry-redact';
105
149
  };
150
+
106
151
  type UnitOptionEntryQuestionProps = CommonQuestionProps & {
107
- type: 'unit-option';
108
- conditionalFieldName: string;
109
- options: UnitOption[];
110
- };
111
- export type QuestionProps = BooleanQuestionProps | CheckboxQuestionProps | DateQuestionProps | DatePeriodQuestionProps | DateTimeQuestionProps | ManageListQuestionProps | EmailQuestionProps | MultiFieldInputQuestionProps | NumberEntryQuestionProps | RadioQuestionProps | SelectQuestionProps | SingleLineInputQuestionProps | SiteAddressQuestionProps | TextEntryQuestionProps | TextEntryRedactQuestionProps | UnitOptionEntryQuestionProps;
112
- export {};
113
- //# sourceMappingURL=question-props.d.ts.map
152
+ type: 'unit-option';
153
+ conditionalFieldName: string;
154
+ options: UnitOption[];
155
+ };
156
+
157
+ export type QuestionProps =
158
+ | BooleanQuestionProps
159
+ | CheckboxQuestionProps
160
+ | DateQuestionProps
161
+ | DatePeriodQuestionProps
162
+ | DateTimeQuestionProps
163
+ | ManageListQuestionProps
164
+ | EmailQuestionProps
165
+ | MultiFieldInputQuestionProps
166
+ | NumberEntryQuestionProps
167
+ | RadioQuestionProps
168
+ | SelectQuestionProps
169
+ | SingleLineInputQuestionProps
170
+ | SiteAddressQuestionProps
171
+ | TextEntryQuestionProps
172
+ | TextEntryRedactQuestionProps
173
+ | UnitOptionEntryQuestionProps;
@@ -1 +1 @@
1
- {"version":3,"file":"question-props.d.ts","sourceRoot":"","sources":["../../../src/questions/question-props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,KAAK,aAAa,GACf,SAAS,GACT,UAAU,GACV,MAAM,GACN,aAAa,GACb,WAAW,GACX,OAAO,GACP,aAAa,GACb,mBAAmB,GACnB,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,mBAAmB,GACnB,cAAc,GACd,YAAY,GACZ,mBAAmB,GACnB,aAAa,CAAC;AAEjB,KAAK,mBAAmB,GAAG,IAAI,CAAC,kBAAkB,EAAE,YAAY,CAAC,GAAG;IACnE,IAAI,EAAE,aAAa,CAAC;CACpB,CAAC;AAEF,KAAK,MAAM,GACR;IACA,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,WAAW,CAAC,EAAE;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,IAAI,CAAC,EAAE,MAAM,C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GAAG,mBAAmB,GAAG;IACnD,IAAI,EAAE,YAAY,CAAC;CACnB,CAAC;AAEF,KAAK,4BAA4B,GAAG,mBAAmB,GAAG;IACzD,IAAI,EAAE,mBAAmB,CAAC;CAC1B,CAAC;AAEF,KAAK,4BAA4B,GAAG,mBAAmB,GAAG;IACzD,IAAI,EAAE,aAAa,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,OAAO,EAAE,UAAU,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GACtB,oBAAoB,GACpB,qBAAqB,GACrB,iBAAiB,GACjB,uBAAuB,GACvB,qBAAqB,GACrB,uBAAuB,GACvB,kBAAkB,GAClB,4BAA4B,GAC5B,wBAAwB,GACxB,kBAAkB,GAClB,mBAAmB,GACnB,4BAA4B,GAC5B,wBAAwB,GACxB,sBAAsB,GACtB,4BAA4B,GAC5B,4BAA4B,CAAC"}
1
+ {"version":3,"file":"question-props.d.ts","sourceRoot":"","sources":["../../../src/questions/question-props.js"],"names":[],"mappings":""}
@@ -2,48 +2,54 @@ import type { RouteParams } from '#src/journey/journey-types.d.ts';
2
2
  import type ManageListQuestion from '#src/components/manage-list/question.js';
3
3
  import type BaseValidator from '../validator/base-validator.js';
4
4
  import type { JourneyResponse } from '../journey/journey-response.js';
5
+
5
6
  export interface QuestionParameters {
6
- title: string;
7
- question: string;
8
- viewFolder: string;
9
- fieldName: string;
10
- url?: string;
11
- pageTitle?: string;
12
- description?: string;
13
- validators?: BaseValidator[];
14
- html?: string;
15
- hint?: string;
16
- interfaceType?: string;
17
- shouldDisplay?: (response: JourneyResponse) => boolean;
18
- autocomplete?: string;
19
- editable?: boolean;
20
- actionLink?: ActionLink;
21
- viewData?: Record<string, any>;
7
+ title: string;
8
+ question: string;
9
+ viewFolder: string;
10
+ fieldName: string;
11
+ url?: string;
12
+ pageTitle?: string;
13
+ description?: string;
14
+ validators?: BaseValidator[];
15
+ html?: string;
16
+ hint?: string;
17
+ interfaceType?: string;
18
+ shouldDisplay?: (response: JourneyResponse) => boolean;
19
+ autocomplete?: string;
20
+ // is this question editable? defaults to true
21
+ editable?: boolean;
22
+ // override the action link for this question
23
+ actionLink?: ActionLink;
24
+ // static view data for this question
25
+ viewData?: Record<string, any>;
22
26
  }
27
+
23
28
  export interface ActionLink {
24
- text: string;
25
- href: string;
29
+ text: string;
30
+ href: string;
26
31
  }
32
+
27
33
  export interface QuestionViewModel {
28
- question: {
29
- value: string | number | Record<string, any>;
30
- question: string;
31
- fieldName: string;
32
- pageTitle: string;
33
- description?: string;
34
- html?: string;
35
- };
36
- layoutTemplate: string;
37
- pageCaption: string;
38
- continueButtonText: string;
39
- backLink: string;
40
- showBackToListLink: string;
41
- listLink: string;
42
- journeyTitle: string;
43
- [k: string]: any;
34
+ question: {
35
+ value: string | number | Record<string, any>;
36
+ question: string;
37
+ fieldName: string;
38
+ pageTitle: string;
39
+ description?: string;
40
+ html?: string;
41
+ };
42
+ layoutTemplate: string;
43
+ pageCaption: string;
44
+ continueButtonText: string;
45
+ backLink: string;
46
+ showBackToListLink: string;
47
+ listLink: string;
48
+ journeyTitle: string;
49
+ [k: string]: any;
44
50
  }
51
+
45
52
  export interface PrepQuestionForRenderingOptions {
46
- params: RouteParams;
47
- manageListQuestion?: ManageListQuestion;
53
+ params: RouteParams;
54
+ manageListQuestion?: ManageListQuestion;
48
55
  }
49
- //# sourceMappingURL=question-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"question-types.d.ts","sourceRoot":"","sources":["../../../src/questions/question-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,kBAAkB,MAAM,yCAAyC,CAAC;AAC9E,OAAO,KAAK,aAAa,MAAM,gCAAgC,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,CAAC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AE,MAAM,GAAG,GAAG,CAAC;CACjB;AAED,MAAM,WAAW,+BAA+B;IAC/C,MAAM,EAAE,WAAW,CAAC;IACpB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACxC"}
1
+ {"version":3,"file":"question-types.d.ts","sourceRoot":"","sources":["../../../src/questions/question-types.js"],"names":[],"mappings":""}
@@ -16,18 +16,24 @@ export const postcodeMinLength: 5;
16
16
  export default class AddressValidator extends BaseValidator {
17
17
  /**
18
18
  * creates an instance of an AddressValidator
19
- * @param {Object} opts
20
- * @param {boolean} [opts.required]
21
- * @param {{[key: string]: boolean}} [opts.requiredFields]
19
+ * @param {Object} [opts]
20
+ * @param {{addressLine1: boolean, addressLine2: boolean, townCity: boolean, county: boolean, postcode: boolean}} [opts.requiredFields]
22
21
  */
23
- constructor(opts: {
24
- required?: boolean | undefined;
22
+ constructor(opts?: {
25
23
  requiredFields?: {
26
- [key: string]: boolean;
24
+ addressLine1: boolean;
25
+ addressLine2: boolean;
26
+ townCity: boolean;
27
+ county: boolean;
28
+ postcode: boolean;
27
29
  } | undefined;
28
30
  });
29
31
  requiredFields: {
30
- [key: string]: boolean;
32
+ addressLine1: boolean;
33
+ addressLine2: boolean;
34
+ townCity: boolean;
35
+ county: boolean;
36
+ postcode: boolean;
31
37
  } | undefined;
32
38
  /**
33
39
  * validates response body using questionObj fieldname
@@ -1 +1 @@
1
- {"version":3,"file":"address-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/address-validator.js"],"names":[],"mappings":"AAIO,4EAQN;AAGD,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,gCAAiC,GAAG,CAAC;AACrC,gCAAiC,CAAC,CAAC;AACnC,8BAA+B,GAAG,CAAC;AACnC,8BAA+B,CAAC,CAAC;AACjC,gCAAiC,CAAC,CAAC;AACnC,gCAAiC,CAAC,CAAC;AAEnC;;;GAGG;AACH;IACC;;;;;OAKG;IACH,kBAHG;QAAuB,QAAQ;QACS,cAAc;;;KAAC,EAKzD;IADA;;kBAA0C;IAG3C;;;OAGG;IACH,sBAFW,QAAQ,iDAYlB;IA+FD,sBAKC;;CACD;0BA3JyB,qBAAqB"}
1
+ {"version":3,"file":"address-validator.d.ts","sourceRoot":"","sources":["../../../src/validator/address-validator.js"],"names":[],"mappings":"AAIO,4EAQN;AAGD,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,oCAAqC,GAAG,CAAC;AACzC,oCAAqC,CAAC,CAAC;AACvC,gCAAiC,GAAG,CAAC;AACrC,gCAAiC,CAAC,CAAC;AACnC,8BAA+B,GAAG,CAAC;AACnC,8BAA+B,CAAC,CAAC;AACjC,gCAAiC,CAAC,CAAC;AACnC,gCAAiC,CAAC,CAAC;AAEnC;;;GAGG;AACH;IACC;;;;OAIG;IACH,mBAFG;QAAqH,cAAc;0BAA5G,OAAO;0BAAgB,OAAO;sBAAY,OAAO;oBAAU,OAAO;sBAAY,OAAO;;KAAwB,EAKtI;IADA;sBAJyB,OAAO;sBAAgB,OAAO;kBAAY,OAAO;gBAAU,OAAO;kBAAY,OAAO;kBAIpE;IAG3C;;;OAGG;IACH,sBAFW,QAAQ,iDAYlB;IA+FD,sBAKC;;CACD;0BA1JyB,qBAAqB"}
@@ -1,17 +1,17 @@
1
1
  /**
2
2
  * @typedef {Object} MinLength
3
3
  * @property {Number} minLength
4
- * @property {String} minLengthMessage
4
+ * @property {String} [minLengthMessage]
5
5
  */
6
6
  /**
7
7
  * @typedef {Object} MaxLength
8
8
  * @property {Number} maxLength
9
- * @property {String} maxLengthMessage
9
+ * @property {String} [maxLengthMessage]
10
10
  */
11
11
  /**
12
12
  * @typedef {Object} Regex
13
13
  * @property {String | RegExp} regex
14
- * @property {String} regexMessage
14
+ * @property {String} [regexMessage]
15
15
  */
16
16
  export default class StringValidator extends BaseValidator {
17
17
  /**
@@ -44,15 +44,15 @@ export default class StringValidator extends BaseValidator {
44
44
  }
45
45
  export type MinLength = {
46
46
  minLength: number;
47
- minLengthMessage: string;
47
+ minLengthMessage?: string | undefined;
48
48
  };
49
49
  export type MaxLength = {
50
50
  maxLength: number;
51
- maxLengthMessage: string;
51
+ maxLengthMessage?: string | undefined;
52
52
  };
53
53
  export type Regex = {
54
54
  regex: string | RegExp;
55
- regexMessage: string;
55
+ regexMessage?: string | undefined;
56
56
  };
57
57
  import BaseValidator from './base-validator.js';
58
58
  //# sourceMappingURL=string-validator.d.ts.map