@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.
Files changed (37) hide show
  1. package/README.md +70 -246
  2. package/commitlint.config.js +3 -5
  3. package/docs/Email Validation.md +86 -0
  4. package/docs/Getting Started.md +299 -0
  5. package/eslint.config.js +3 -17
  6. package/package.json +4 -1
  7. package/prettier.config.js +7 -0
  8. package/src/components/checkbox/question.d.ts.map +1 -1
  9. package/src/components/checkbox/question.js +3 -2
  10. package/src/components/checkbox/question.test.js +8 -0
  11. package/src/components/conditional/text.njk +1 -0
  12. package/src/components/email/question.d.ts +0 -9
  13. package/src/components/email/question.d.ts.map +1 -1
  14. package/src/components/email/question.js +2 -13
  15. package/src/components/email/question.test.js +19 -0
  16. package/src/components/multi-field-input/question.d.ts +4 -19
  17. package/src/components/multi-field-input/question.d.ts.map +1 -1
  18. package/src/components/multi-field-input/question.js +89 -23
  19. package/src/components/multi-field-input/question.test.js +441 -3
  20. package/src/components/number-entry/question.d.ts.map +1 -1
  21. package/src/components/number-entry/question.js +3 -2
  22. package/src/components/number-entry/question.test.js +17 -0
  23. package/src/components/unit-option-entry/question.d.ts.map +1 -1
  24. package/src/components/unit-option-entry/question.js +3 -1
  25. package/src/components/unit-option-entry/question.test.js +15 -0
  26. package/src/questions/options-question.d.ts +19 -7
  27. package/src/questions/options-question.d.ts.map +1 -1
  28. package/src/questions/options-question.js +9 -7
  29. package/src/questions/question.d.ts +2 -2
  30. package/src/questions/question.js +2 -2
  31. package/test/snapshots/check-your-answers-with-answers.html +1 -1
  32. package/test/utils/question-test-utils.js +2 -1
  33. package/typedefs/journey-types.d.ts +1 -1
  34. package/typedefs/question-props.d.ts +33 -0
  35. package/typedefs/question-types.d.ts +0 -23
  36. package/typedefs/section-types.d.ts +4 -4
  37. 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<br>
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
- return res;
238
+ // Remove trailing <br>
239
+ return res.slice(0, -4);
239
240
  }
240
241
  break;
241
242
  case COMPONENT_TYPES.ADDRESS: {
@@ -15,7 +15,7 @@ export type ManageListRouteParams =
15
15
  manageListItemId: string;
16
16
  manageListQuestion: string;
17
17
  }
18
- | {};
18
+ | object;
19
19
 
20
20
  export interface JourneyAnswers {
21
21
  // if the answer is for a manage list question, the answer will be an array of answer objects
@@ -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;
package/.prettierrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "printWidth": 120,
3
- "tabWidth": 2,
4
- "singleQuote": true,
5
- "useTabs": true,
6
- "semi": true,
7
- "trailingComma": "none",
8
- "bracketSpacing": true,
9
- "arrowParens": "always",
10
- "endOfLine": "lf",
11
- "plugins": []
12
- }