@planning-inspectorate/dynamic-forms 3.17.0 → 3.18.1
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/README.md +70 -246
- package/commitlint.config.js +3 -5
- package/docs/Email Validation.md +86 -0
- package/docs/Getting Started.md +299 -0
- package/eslint.config.js +3 -17
- package/package.json +4 -1
- package/prettier.config.js +7 -0
- package/src/components/checkbox/question.d.ts.map +1 -1
- package/src/components/checkbox/question.js +3 -2
- package/src/components/checkbox/question.test.js +8 -0
- package/src/components/conditional/text.njk +1 -0
- package/src/components/email/question.d.ts +0 -9
- package/src/components/email/question.d.ts.map +1 -1
- package/src/components/email/question.js +2 -13
- package/src/components/email/question.test.js +19 -0
- package/src/components/multi-field-input/question.d.ts +4 -19
- package/src/components/multi-field-input/question.d.ts.map +1 -1
- package/src/components/multi-field-input/question.js +89 -23
- package/src/components/multi-field-input/question.test.js +441 -3
- package/src/components/number-entry/question.d.ts.map +1 -1
- package/src/components/number-entry/question.js +3 -2
- package/src/components/number-entry/question.test.js +17 -0
- package/src/components/unit-option-entry/question.d.ts.map +1 -1
- package/src/components/unit-option-entry/question.js +3 -1
- package/src/components/unit-option-entry/question.test.js +15 -0
- package/src/questions/options-question.d.ts +19 -7
- package/src/questions/options-question.d.ts.map +1 -1
- package/src/questions/options-question.js +9 -7
- package/src/questions/question.d.ts +2 -2
- package/src/questions/question.js +2 -2
- package/test/snapshots/check-your-answers-with-answers.html +1 -1
- package/test/utils/question-test-utils.js +2 -1
- package/typedefs/journey-types.d.ts +1 -1
- package/typedefs/question-props.d.ts +33 -0
- package/typedefs/question-types.d.ts +0 -23
- package/typedefs/section-types.d.ts +4 -4
- package/.prettierrc +0 -12
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
Travel Companions
|
|
147
147
|
</dt>
|
|
148
148
|
<dd class="govuk-summary-list__value">
|
|
149
|
-
test<br>1
|
|
149
|
+
test<br>1
|
|
150
150
|
</dd>
|
|
151
151
|
<dd class="govuk-summary-list__actions">
|
|
152
152
|
<a class="govuk-link" href="questions/companions">Change<span class="govuk-visually-hidden"> Enter the names and ages of your travel companions.</span></a>
|
|
@@ -235,7 +235,8 @@ export function mockAnswer(q) {
|
|
|
235
235
|
for (const field of q.inputFields) {
|
|
236
236
|
res += mockInputFieldValue(field) + '<br>';
|
|
237
237
|
}
|
|
238
|
-
|
|
238
|
+
// Remove trailing <br>
|
|
239
|
+
return res.slice(0, -4);
|
|
239
240
|
}
|
|
240
241
|
break;
|
|
241
242
|
case COMPONENT_TYPES.ADDRESS: {
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
import type { QuestionParameters } from './question-types.d.ts';
|
|
2
|
+
import type { Question } from '../src/questions/question.js';
|
|
3
|
+
import type { Journey } from '../src/journey/journey.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Context passed to the custom summary formatter
|
|
7
|
+
*/
|
|
8
|
+
export interface SummaryFormatterContext<TAnswer = unknown> {
|
|
9
|
+
/** The raw answer value */
|
|
10
|
+
answer: TAnswer;
|
|
11
|
+
/** The default display value */
|
|
12
|
+
formattedAnswer: string;
|
|
13
|
+
/** The question instance */
|
|
14
|
+
question: Question;
|
|
15
|
+
/** The journey instance */
|
|
16
|
+
journey: Journey;
|
|
17
|
+
/** The section segment */
|
|
18
|
+
sectionSegment: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Custom function to format the summary display value
|
|
23
|
+
*/
|
|
24
|
+
export type SummaryValueFormatter<TAnswer = unknown> = (context: SummaryFormatterContext<TAnswer>) => string;
|
|
2
25
|
|
|
3
26
|
export type QuestionTypes =
|
|
4
27
|
| 'boolean'
|
|
@@ -74,6 +97,7 @@ interface InputField {
|
|
|
74
97
|
formatJoinString?: string; // used by formatAnswerForSummary (e.g. task list display), effective default to line break
|
|
75
98
|
formatPrefix?: string; // used by formatAnswerForSummary (e.g. task list display), to prefix answer
|
|
76
99
|
formatTextFunction?: (text: string) => string; // used to format the answer for display and value in question
|
|
100
|
+
formatSummaryValue?: (context: InputFieldSummaryContext) => string; // used to format the answer for summary display only (not escaped)
|
|
77
101
|
attributes?: Record<string, string>; // used to add HTML attributes to the field
|
|
78
102
|
suffix?: Affix; // used to add a suffix to the field
|
|
79
103
|
prefix?: Affix; // used to add a prefix to the field
|
|
@@ -83,6 +107,15 @@ interface InputField {
|
|
|
83
107
|
pattern?: string; // Used for backwards-compatibility for older iOS devices in numeric input fields
|
|
84
108
|
}
|
|
85
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Context passed to InputField.formatSummaryValue
|
|
112
|
+
* Extends the base SummaryFormatterContext with field-specific properties
|
|
113
|
+
*/
|
|
114
|
+
interface InputFieldSummaryContext extends SummaryFormatterContext {
|
|
115
|
+
/** The input field configuration */
|
|
116
|
+
field: InputField;
|
|
117
|
+
}
|
|
118
|
+
|
|
86
119
|
/*
|
|
87
120
|
* UnitOptions are the options displayed in the radio format - in this case the value
|
|
88
121
|
* represents the unit.
|
|
@@ -3,29 +3,6 @@ import type ManageListQuestion from '#src/components/manage-list/question.js';
|
|
|
3
3
|
import type BaseValidator from '#src/validator/base-validator.js';
|
|
4
4
|
import type { JourneyResponse } from '#src/journey/journey-response.js';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Context passed to the custom summary formatter
|
|
8
|
-
*/
|
|
9
|
-
export interface SummaryFormatterContext<TAnswer = unknown> {
|
|
10
|
-
/** The raw answer value */
|
|
11
|
-
answer: TAnswer;
|
|
12
|
-
/** The default display value */
|
|
13
|
-
formattedAnswer: string;
|
|
14
|
-
/** The question instance */
|
|
15
|
-
question: import('./question.js').Question;
|
|
16
|
-
/** The journey instance */
|
|
17
|
-
journey: import('../journey/journey.js').Journey;
|
|
18
|
-
/** The section segment */
|
|
19
|
-
sectionSegment: string;
|
|
20
|
-
/** The selected option objects (for options-based questions) */
|
|
21
|
-
selectedOptions?: import('./options-question.js').Option[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Custom function to format the summary display value
|
|
26
|
-
*/
|
|
27
|
-
export type SummaryValueFormatter<TAnswer = unknown> = (context: SummaryFormatterContext<TAnswer>) => string;
|
|
28
|
-
|
|
29
6
|
export interface QuestionParameters {
|
|
30
7
|
title: string;
|
|
31
8
|
question: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { JourneyResponse } from '#src/journey/journey-response.js';
|
|
2
|
-
import ManageListQuestion from '#src/components/manage-list/question.js';
|
|
3
|
-
import { Question } from '#src/questions/question.js';
|
|
4
|
-
import { RouteParams } from './journey-types.d.ts';
|
|
1
|
+
import type { JourneyResponse } from '#src/journey/journey-response.js';
|
|
2
|
+
import type ManageListQuestion from '#src/components/manage-list/question.js';
|
|
3
|
+
import type { Question } from '#src/questions/question.js';
|
|
4
|
+
import type { RouteParams } from './journey-types.d.ts';
|
|
5
5
|
|
|
6
6
|
export interface GetNextQuestionParams {
|
|
7
7
|
questionFieldName: string;
|