@planning-inspectorate/dynamic-forms 3.8.2 → 3.9.0
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 +14 -0
- package/package.json +3 -3
- package/src/components/select/index.njk +22 -18
- package/src/components/select/question.js +5 -0
- package/src/components/select/question.test.js +77 -1
- package/src/index.js +2 -2
- package/src/questions/{question-props.ts → question-props.d.ts} +2 -1
- package/src/questions/question-props.js +1 -0
- package/src/questions/question-types.js +1 -0
- package/test/snapshots/travel-class.html +17 -17
- package/tsconfig.json +1 -1
- package/types/move-types.d.ts +2 -0
- package/types/move-types.d.ts.map +1 -0
- package/types/src/components/select/question.d.ts +4 -1
- package/types/src/components/select/question.d.ts.map +1 -1
- package/types/src/index.d.ts +2 -2
- package/types/src/questions/question-props.d.ts +138 -77
- package/types/src/questions/question-props.d.ts.map +1 -1
- package/types/src/questions/question-types.d.ts +43 -37
- package/types/src/questions/question-types.d.ts.map +1 -1
- /package/src/questions/{question-types.ts → question-types.d.ts} +0 -0
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.
|
|
3
|
+
"version": "3.9.0",
|
|
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",
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
{% from "govuk/components/button/macro.njk" import govukButton %}
|
|
5
5
|
|
|
6
6
|
{% block head %}
|
|
7
|
-
|
|
7
|
+
{% if not question.disableAccessibleAutocomplete %}
|
|
8
|
+
<link rel="stylesheet" href="/assets/css/accessible-autocomplete.min.css"/>
|
|
9
|
+
{% endif %}
|
|
8
10
|
|
|
9
11
|
{{ super() }}
|
|
10
12
|
{% endblock %}
|
|
@@ -61,22 +63,24 @@
|
|
|
61
63
|
</form>
|
|
62
64
|
</div>
|
|
63
65
|
</div>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if
|
|
67
|
-
accessibleAutocomplete
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
{% if not question.disableAccessibleAutocomplete %}
|
|
67
|
+
<script src="/assets/js/accessible-autocomplete.min.js"></script>
|
|
68
|
+
<script {% if cspNonce %}nonce={{ cspNonce }}{% endif %}>
|
|
69
|
+
if (window.accessibleAutocomplete) {
|
|
70
|
+
accessibleAutocomplete.enhanceSelectElement({
|
|
71
|
+
selectElement: document.querySelector('#{{ question.fieldName }}'),
|
|
72
|
+
onConfirm: () => {
|
|
73
|
+
let input = document.querySelector('#{{ question.fieldName }}');
|
|
74
|
+
let select = document.querySelector('#{{ question.fieldName }}-select');
|
|
75
|
+
let options = Array.from(select.options);
|
|
76
|
+
if (!input.value || !options.some(option => option.innerText === input.value)) {
|
|
77
|
+
select.options.selectedIndex = -1;
|
|
78
|
+
} else {
|
|
79
|
+
select.options.selectedIndex = options.findIndex(option => option.innerText === input.value);
|
|
80
|
+
}
|
|
77
81
|
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
</script>
|
|
85
|
+
{% endif %}
|
|
82
86
|
{% endblock %}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import OptionsQuestion from '../../questions/options-question.js';
|
|
2
2
|
|
|
3
3
|
export default class SelectQuestion extends OptionsQuestion {
|
|
4
|
+
#disableAccessibleAutocomplete;
|
|
4
5
|
/**
|
|
5
6
|
* @param {Object} params
|
|
6
7
|
* @param {string} params.title
|
|
@@ -14,6 +15,7 @@ export default class SelectQuestion extends OptionsQuestion {
|
|
|
14
15
|
* @param {string} [params.label]
|
|
15
16
|
* @param {string} [params.html]
|
|
16
17
|
* @param {string} [params.legend] - optional legend, used instead of h1
|
|
18
|
+
* @param {string} [params.disableAccessibleAutocomplete]
|
|
17
19
|
* @param {Array.<import('../../questions/options-question.js').Option>} params.options
|
|
18
20
|
* @param {Object<string, any>} [params.viewData]
|
|
19
21
|
* @param {Array.<import('#base-validator').BaseValidator>} [params.validators]
|
|
@@ -30,6 +32,7 @@ export default class SelectQuestion extends OptionsQuestion {
|
|
|
30
32
|
label,
|
|
31
33
|
html,
|
|
32
34
|
legend,
|
|
35
|
+
disableAccessibleAutocomplete,
|
|
33
36
|
options,
|
|
34
37
|
validators,
|
|
35
38
|
viewData
|
|
@@ -51,6 +54,7 @@ export default class SelectQuestion extends OptionsQuestion {
|
|
|
51
54
|
this.html = html;
|
|
52
55
|
this.label = label;
|
|
53
56
|
this.legend = legend;
|
|
57
|
+
this.#disableAccessibleAutocomplete = disableAccessibleAutocomplete;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
/**
|
|
@@ -59,6 +63,7 @@ export default class SelectQuestion extends OptionsQuestion {
|
|
|
59
63
|
addCustomDataToViewModel(viewModel) {
|
|
60
64
|
viewModel.question.label = this.label;
|
|
61
65
|
viewModel.question.legend = this.legend;
|
|
66
|
+
viewModel.question.disableAccessibleAutocomplete = this.#disableAccessibleAutocomplete;
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { describe, it } from 'node:test';
|
|
1
|
+
import { describe, it, mock } from 'node:test';
|
|
2
2
|
import assert from 'node:assert';
|
|
3
3
|
import ValidOptionValidator from '../../validator/valid-option-validator.js';
|
|
4
4
|
import SelectQuestion from './question.js';
|
|
5
5
|
import nunjucks from 'nunjucks';
|
|
6
|
+
import { configureNunjucksTestEnv } from '#test/utils/nunjucks.js';
|
|
6
7
|
|
|
7
8
|
const TITLE = 'Select question';
|
|
8
9
|
const QUESTION = 'A select question';
|
|
@@ -94,6 +95,81 @@ describe('./src/dynamic-forms/components/select/question.js', () => {
|
|
|
94
95
|
assert.strictEqual(preppedQuestion.question.label, LABEL);
|
|
95
96
|
});
|
|
96
97
|
|
|
98
|
+
it('should pass in disableAccessibleAutocomplete property to view', (ctx) => {
|
|
99
|
+
nunjucks.render = ctx.mock.fn();
|
|
100
|
+
nunjucks.render.mock.mockImplementation(() => {});
|
|
101
|
+
|
|
102
|
+
const selectQuestion = new SelectQuestion({
|
|
103
|
+
title: TITLE,
|
|
104
|
+
question: QUESTION,
|
|
105
|
+
description: DESCRIPTION,
|
|
106
|
+
fieldName: FIELDNAME,
|
|
107
|
+
html: HTML,
|
|
108
|
+
label: LABEL,
|
|
109
|
+
options: OPTIONS,
|
|
110
|
+
disableAccessibleAutocomplete: true
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const customViewData = { hello: 'hi' };
|
|
114
|
+
|
|
115
|
+
const preppedQuestion = selectQuestion.prepQuestionForRendering(SECTION, JOURNEY, customViewData);
|
|
116
|
+
|
|
117
|
+
assert.strictEqual(preppedQuestion.question.disableAccessibleAutocomplete, true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should include accessible autocomplete by default', async () => {
|
|
121
|
+
const selectQuestion = new SelectQuestion({
|
|
122
|
+
title: TITLE,
|
|
123
|
+
question: QUESTION,
|
|
124
|
+
description: DESCRIPTION,
|
|
125
|
+
fieldName: FIELDNAME,
|
|
126
|
+
html: HTML,
|
|
127
|
+
label: LABEL,
|
|
128
|
+
options: OPTIONS
|
|
129
|
+
});
|
|
130
|
+
const viewModel = selectQuestion.prepQuestionForRendering(SECTION, JOURNEY, {
|
|
131
|
+
layoutTemplate: 'views/layout-journey.njk'
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const nunjucks = configureNunjucksTestEnv();
|
|
135
|
+
const mockRes = {
|
|
136
|
+
render: mock.fn((view, data) => nunjucks.render(view + '.njk', data))
|
|
137
|
+
};
|
|
138
|
+
selectQuestion.renderAction(mockRes, viewModel);
|
|
139
|
+
|
|
140
|
+
assert.strictEqual(mockRes.render.mock.callCount(), 1);
|
|
141
|
+
const view = mockRes.render.mock.calls[0].result;
|
|
142
|
+
assert.ok(view);
|
|
143
|
+
assert.match(view, /accessible-autocomplete\.min\.js/);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should not include accessible autocomplete if configured', async () => {
|
|
147
|
+
const selectQuestion = new SelectQuestion({
|
|
148
|
+
title: TITLE,
|
|
149
|
+
question: QUESTION,
|
|
150
|
+
description: DESCRIPTION,
|
|
151
|
+
fieldName: FIELDNAME,
|
|
152
|
+
html: HTML,
|
|
153
|
+
label: LABEL,
|
|
154
|
+
options: OPTIONS,
|
|
155
|
+
disableAccessibleAutocomplete: true
|
|
156
|
+
});
|
|
157
|
+
const viewModel = selectQuestion.prepQuestionForRendering(SECTION, JOURNEY, {
|
|
158
|
+
layoutTemplate: 'views/layout-journey.njk'
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const nunjucks = configureNunjucksTestEnv();
|
|
162
|
+
const mockRes = {
|
|
163
|
+
render: mock.fn((view, data) => nunjucks.render(view + '.njk', data))
|
|
164
|
+
};
|
|
165
|
+
selectQuestion.renderAction(mockRes, viewModel);
|
|
166
|
+
|
|
167
|
+
assert.strictEqual(mockRes.render.mock.callCount(), 1);
|
|
168
|
+
const view = mockRes.render.mock.calls[0].result;
|
|
169
|
+
assert.ok(view);
|
|
170
|
+
assert.doesNotMatch(view, /accessible-autocomplete\.min\.js/);
|
|
171
|
+
});
|
|
172
|
+
|
|
97
173
|
it('should add selected attribute to chosen option', (ctx) => {
|
|
98
174
|
nunjucks.render = ctx.mock.fn();
|
|
99
175
|
nunjucks.render.mock.mockImplementation(() => {});
|
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.
|
|
50
|
-
export * from './questions/question-types.
|
|
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'
|
|
@@ -129,6 +129,7 @@ type RadioQuestionProps = CommonQuestionProps & {
|
|
|
129
129
|
type SelectQuestionProps = CommonQuestionProps & {
|
|
130
130
|
type: 'select';
|
|
131
131
|
options: Option[];
|
|
132
|
+
disableAccessibleAutocomplete?: boolean;
|
|
132
133
|
};
|
|
133
134
|
|
|
134
135
|
type SingleLineInputQuestionProps = CommonQuestionProps & {
|
|
@@ -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
|
|
@@ -26,21 +26,21 @@
|
|
|
26
26
|
</form>
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
<script src="/assets/js/accessible-autocomplete.min.js"></script>
|
|
30
|
+
<script >
|
|
31
|
+
if (window.accessibleAutocomplete) {
|
|
32
|
+
accessibleAutocomplete.enhanceSelectElement({
|
|
33
|
+
selectElement: document.querySelector('#travelClass'),
|
|
34
|
+
onConfirm: () => {
|
|
35
|
+
let input = document.querySelector('#travelClass');
|
|
36
|
+
let select = document.querySelector('#travelClass-select');
|
|
37
|
+
let options = Array.from(select.options);
|
|
38
|
+
if (!input.value || !options.some(option => option.innerText === input.value)) {
|
|
39
|
+
select.options.selectedIndex = -1;
|
|
40
|
+
} else {
|
|
41
|
+
select.options.selectedIndex = options.findIndex(option => option.innerText === input.value);
|
|
42
|
+
}
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
</script>
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
</script>
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"move-types.d.ts","sourceRoot":"","sources":["../move-types.js"],"names":[],"mappings":""}
|
|
@@ -12,11 +12,12 @@ export default class SelectQuestion extends OptionsQuestion {
|
|
|
12
12
|
* @param {string} [params.label]
|
|
13
13
|
* @param {string} [params.html]
|
|
14
14
|
* @param {string} [params.legend] - optional legend, used instead of h1
|
|
15
|
+
* @param {string} [params.disableAccessibleAutocomplete]
|
|
15
16
|
* @param {Array.<import('../../questions/options-question.js').Option>} params.options
|
|
16
17
|
* @param {Object<string, any>} [params.viewData]
|
|
17
18
|
* @param {Array.<import('#base-validator').BaseValidator>} [params.validators]
|
|
18
19
|
*/
|
|
19
|
-
constructor({ title, question, fieldName, viewFolder, url, hint, pageTitle, description, label, html, legend, options, validators, viewData }: {
|
|
20
|
+
constructor({ title, question, fieldName, viewFolder, url, hint, pageTitle, description, label, html, legend, disableAccessibleAutocomplete, options, validators, viewData }: {
|
|
20
21
|
title: string;
|
|
21
22
|
question: string;
|
|
22
23
|
fieldName: string;
|
|
@@ -28,6 +29,7 @@ export default class SelectQuestion extends OptionsQuestion {
|
|
|
28
29
|
label?: string | undefined;
|
|
29
30
|
html?: string | undefined;
|
|
30
31
|
legend?: string | undefined;
|
|
32
|
+
disableAccessibleAutocomplete?: string | undefined;
|
|
31
33
|
options: Array<import("../../questions/options-question.js").Option>;
|
|
32
34
|
viewData?: {
|
|
33
35
|
[x: string]: any;
|
|
@@ -46,6 +48,7 @@ export default class SelectQuestion extends OptionsQuestion {
|
|
|
46
48
|
* @returns {Array.<Object>}
|
|
47
49
|
*/
|
|
48
50
|
formatAnswerForSummary(sectionSegment: string, journey: Journey, answer: Object): Array<Object>;
|
|
51
|
+
#private;
|
|
49
52
|
}
|
|
50
53
|
import OptionsQuestion from '../../questions/options-question.js';
|
|
51
54
|
//# sourceMappingURL=question.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/select/question.js"],"names":[],"mappings":"AAEA;
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/select/question.js"],"names":[],"mappings":"AAEA;IAEC;;;;;;;;;;;;;;;;;OAiBG;IACH,8KAhBG;QAAuB,KAAK,EAApB,MAAM;QACS,QAAQ,EAAvB,MAAM;QACS,SAAS,EAAxB,MAAM;QACU,UAAU;QACV,GAAG;QACH,IAAI;QACJ,SAAS;QACT,WAAW;QACX,KAAK;QACL,IAAI;QACJ,MAAM;QACN,6BAA6B;QACwB,OAAO,EAA5E,KAAK,CAAE,OAAO,qCAAqC,EAAE,MAAM,CAAC;QAC/B,QAAQ;;;QACoB,UAAU;KAAC,EAqC9E;IAHA,0BAAkB;IAClB,2BAAoB;IAarB;;;;;;;;OAQG;IACH,wDAJW,OAAO,UADP,MAAM,GAGJ,KAAK,CAAE,MAAM,CAAC,CAS1B;;CACD;4BArF2B,qCAAqC"}
|
package/types/src/index.d.ts
CHANGED
|
@@ -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.
|
|
27
|
-
export * from "./questions/question-types.
|
|
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,174 @@
|
|
|
1
|
-
import type { QuestionParameters } from '#question-types';
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
82
|
+
type: 'boolean';
|
|
83
|
+
options?: Option[];
|
|
84
|
+
interfaceType?: 'checkbox' | 'radio';
|
|
55
85
|
};
|
|
86
|
+
|
|
56
87
|
type CheckboxQuestionProps = CommonQuestionProps & {
|
|
57
|
-
|
|
58
|
-
|
|
88
|
+
type: 'checkbox';
|
|
89
|
+
options: Option[];
|
|
59
90
|
};
|
|
91
|
+
|
|
60
92
|
type DateQuestionProps = CommonQuestionProps & {
|
|
61
|
-
|
|
93
|
+
type: 'date';
|
|
62
94
|
};
|
|
95
|
+
|
|
63
96
|
type DatePeriodQuestionProps = CommonQuestionProps & {
|
|
64
|
-
|
|
97
|
+
type: 'date-period';
|
|
65
98
|
};
|
|
99
|
+
|
|
66
100
|
type DateTimeQuestionProps = CommonQuestionProps & {
|
|
67
|
-
|
|
101
|
+
type: 'date-time';
|
|
68
102
|
};
|
|
103
|
+
|
|
69
104
|
type ManageListQuestionProps = CommonQuestionProps & {
|
|
70
|
-
|
|
105
|
+
type: 'manage-list';
|
|
71
106
|
};
|
|
107
|
+
|
|
72
108
|
type EmailQuestionProps = CommonQuestionProps & {
|
|
73
|
-
|
|
109
|
+
type: 'email';
|
|
74
110
|
};
|
|
111
|
+
|
|
75
112
|
type MultiFieldInputQuestionProps = CommonQuestionProps & {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
83
|
-
|
|
120
|
+
type: 'number';
|
|
121
|
+
suffix?: string;
|
|
84
122
|
};
|
|
123
|
+
|
|
85
124
|
type RadioQuestionProps = CommonQuestionProps & {
|
|
86
|
-
|
|
87
|
-
|
|
125
|
+
type: 'radio';
|
|
126
|
+
options: Option[];
|
|
88
127
|
};
|
|
128
|
+
|
|
89
129
|
type SelectQuestionProps = CommonQuestionProps & {
|
|
90
|
-
|
|
91
|
-
|
|
130
|
+
type: 'select';
|
|
131
|
+
options: Option[];
|
|
132
|
+
disableAccessibleAutocomplete?: boolean;
|
|
92
133
|
};
|
|
134
|
+
|
|
93
135
|
type SingleLineInputQuestionProps = CommonQuestionProps & {
|
|
94
|
-
|
|
95
|
-
|
|
136
|
+
type: 'single-line-input';
|
|
137
|
+
inputAttributes?: Record<string, string>;
|
|
96
138
|
};
|
|
139
|
+
|
|
97
140
|
type SiteAddressQuestionProps = CommonQuestionProps & {
|
|
98
|
-
|
|
141
|
+
type: 'site-address';
|
|
99
142
|
};
|
|
143
|
+
|
|
100
144
|
type TextEntryQuestionProps = CommonQuestionProps & {
|
|
101
|
-
|
|
145
|
+
type: 'text-entry';
|
|
102
146
|
};
|
|
147
|
+
|
|
103
148
|
type TextEntryRedactQuestionProps = CommonQuestionProps & {
|
|
104
|
-
|
|
149
|
+
type: 'text-entry-redact';
|
|
105
150
|
};
|
|
151
|
+
|
|
106
152
|
type UnitOptionEntryQuestionProps = CommonQuestionProps & {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export
|
|
113
|
-
|
|
153
|
+
type: 'unit-option';
|
|
154
|
+
conditionalFieldName: string;
|
|
155
|
+
options: UnitOption[];
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type QuestionProps =
|
|
159
|
+
| BooleanQuestionProps
|
|
160
|
+
| CheckboxQuestionProps
|
|
161
|
+
| DateQuestionProps
|
|
162
|
+
| DatePeriodQuestionProps
|
|
163
|
+
| DateTimeQuestionProps
|
|
164
|
+
| ManageListQuestionProps
|
|
165
|
+
| EmailQuestionProps
|
|
166
|
+
| MultiFieldInputQuestionProps
|
|
167
|
+
| NumberEntryQuestionProps
|
|
168
|
+
| RadioQuestionProps
|
|
169
|
+
| SelectQuestionProps
|
|
170
|
+
| SingleLineInputQuestionProps
|
|
171
|
+
| SiteAddressQuestionProps
|
|
172
|
+
| TextEntryQuestionProps
|
|
173
|
+
| TextEntryRedactQuestionProps
|
|
174
|
+
| UnitOptionEntryQuestionProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question-props.d.ts","sourceRoot":"","sources":["../../../src/questions/question-props.
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
29
|
+
text: string;
|
|
30
|
+
href: string;
|
|
26
31
|
}
|
|
32
|
+
|
|
27
33
|
export interface QuestionViewModel {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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.
|
|
1
|
+
{"version":3,"file":"question-types.d.ts","sourceRoot":"","sources":["../../../src/questions/question-types.js"],"names":[],"mappings":""}
|
|
File without changes
|