@planning-inspectorate/dynamic-forms 3.15.6 → 3.17.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/.gitattributes +3 -0
- package/.prettierrc +1 -0
- package/README.md +123 -4
- package/package.json +6 -4
- package/{types/src → src}/components/address/question.d.ts +6 -2
- package/src/components/address/question.d.ts.map +1 -0
- package/src/components/address/question.js +7 -19
- package/{types/src → src}/components/boolean/question.d.ts +2 -2
- package/src/components/boolean/question.d.ts.map +1 -0
- package/src/components/boolean/question.js +1 -1
- package/src/components/checkbox/question.d.ts +9 -0
- package/src/components/checkbox/question.d.ts.map +1 -0
- package/src/components/checkbox/question.js +37 -54
- package/src/components/checkbox/question.test.js +170 -27
- package/{types/src → src}/components/date/question.d.ts +2 -2
- package/src/components/date/question.d.ts.map +1 -0
- package/src/components/date/question.js +7 -16
- package/{types/src → src}/components/date-period/question.d.ts +12 -4
- package/src/components/date-period/question.d.ts.map +1 -0
- package/src/components/date-period/question.js +2 -3
- package/{types/src → src}/components/date-time/question.d.ts +2 -2
- package/src/components/date-time/question.d.ts.map +1 -0
- package/src/components/date-time/question.js +5 -14
- package/src/components/email/question.d.ts +23 -0
- package/src/components/email/question.d.ts.map +1 -0
- package/src/components/email/question.js +1 -9
- package/src/components/manage-list/answer-summary-list.njk +1 -1
- package/src/components/manage-list/manage-list-actions.d.ts.map +1 -0
- package/src/components/manage-list/manage-list-section.d.ts.map +1 -0
- package/{types/src → src}/components/manage-list/question.d.ts +6 -3
- package/src/components/manage-list/question.d.ts.map +1 -0
- package/src/components/manage-list/question.js +5 -2
- package/{types/src → src}/components/manage-list/utils.d.ts +3 -3
- package/src/components/manage-list/utils.d.ts.map +1 -0
- package/src/components/manage-list/utils.js +2 -2
- package/src/components/multi-field-input/question.d.ts +52 -0
- package/src/components/multi-field-input/question.d.ts.map +1 -0
- package/src/components/multi-field-input/question.js +5 -13
- package/src/components/number-entry/question.d.ts +12 -0
- package/src/components/number-entry/question.d.ts.map +1 -0
- package/src/components/number-entry/question.js +4 -22
- package/src/components/radio/question.d.ts +11 -0
- package/src/components/radio/question.d.ts.map +1 -0
- package/src/components/radio/question.js +30 -51
- package/src/components/radio/question.test.js +139 -60
- package/src/components/select/question.d.ts +12 -0
- package/src/components/select/question.d.ts.map +1 -0
- package/src/components/select/question.js +5 -48
- package/{types/src → src}/components/single-line-input/question.d.ts +2 -2
- package/src/components/single-line-input/question.d.ts.map +1 -0
- package/src/components/single-line-input/question.js +2 -2
- package/{types/src → src}/components/text-entry/question.d.ts +3 -3
- package/src/components/text-entry/question.d.ts.map +1 -0
- package/src/components/text-entry/question.js +2 -2
- package/{types/src → src}/components/text-entry-redact/question.d.ts +8 -9
- package/src/components/text-entry-redact/question.d.ts.map +1 -0
- package/src/components/text-entry-redact/question.js +5 -2
- package/{types/src → src}/components/unit-option-entry/question.d.ts +12 -8
- package/src/components/unit-option-entry/question.d.ts.map +1 -0
- package/src/components/unit-option-entry/question.js +5 -6
- package/src/components/utils/component-types.d.ts.map +1 -0
- package/src/components/utils/persisted-number-answer.d.ts.map +1 -0
- package/src/components/utils/question-has-answer.d.ts.map +1 -0
- package/src/components/utils/question-has-answer.js +1 -1
- package/src/components/utils/question-utils.d.ts +33 -0
- package/src/components/utils/question-utils.d.ts.map +1 -0
- package/src/components/utils/question-utils.js +31 -2
- package/src/components/utils/question-utils.test.js +89 -2
- package/{types/src → src}/controller.d.ts +2 -7
- package/src/controller.d.ts.map +1 -0
- package/src/controller.js +3 -10
- package/{types/src → src}/index.d.ts +4 -3
- package/src/index.d.ts.map +1 -0
- package/src/index.js +6 -4
- package/src/journey/journey-response.d.ts +28 -0
- package/src/journey/journey-response.d.ts.map +1 -0
- package/src/journey/journey-response.js +4 -8
- package/{types/src → src}/journey/journey.d.ts +8 -8
- package/src/journey/journey.d.ts.map +1 -0
- package/src/journey/journey.js +6 -6
- package/src/lib/address-utils.d.ts.map +1 -0
- package/src/lib/address.d.ts.map +1 -0
- package/src/lib/date-utils.d.ts.map +1 -0
- package/src/lib/session-answer-store.d.ts.map +1 -0
- package/src/lib/utils.d.ts.map +1 -0
- package/src/lib/uuid.d.ts.map +1 -0
- package/src/middleware/build-get-journey.d.ts.map +1 -0
- package/src/middleware/redirect-to-unanswered-question.d.ts +12 -0
- package/src/middleware/redirect-to-unanswered-question.d.ts.map +1 -0
- package/src/middleware/redirect-to-unanswered-question.js +1 -1
- package/src/questions/create-questions.d.ts +18 -0
- package/src/questions/create-questions.d.ts.map +1 -0
- package/src/questions/create-questions.js +3 -3
- package/{types/src → src}/questions/options-question.d.ts +7 -7
- package/src/questions/options-question.d.ts.map +1 -0
- package/src/questions/options-question.js +29 -4
- package/src/questions/options-question.test.js +106 -0
- package/{types/src → src}/questions/question.d.ts +48 -79
- package/src/questions/question.d.ts.map +1 -0
- package/src/questions/question.js +83 -60
- package/src/questions/question.test.js +86 -0
- package/src/questions/questions.d.ts +3 -0
- package/src/questions/questions.d.ts.map +1 -0
- package/src/questions/questions.js +1 -1
- package/{types/src → src}/section.d.ts +16 -15
- package/src/section.d.ts.map +1 -0
- package/src/section.js +12 -14
- package/src/validator/address-validator.d.ts.map +1 -0
- package/src/validator/base-validator.d.ts.map +1 -0
- package/src/validator/conditional-required-validator.d.ts.map +1 -0
- package/src/validator/confirmation-checkbox-validator.d.ts.map +1 -0
- package/src/validator/coordinates-validator.d.ts.map +1 -0
- package/src/validator/cross-question-validator.d.ts.map +1 -0
- package/src/validator/date-period-validator.d.ts.map +1 -0
- package/src/validator/date-time-validator.d.ts.map +1 -0
- package/src/validator/date-validator.d.ts.map +1 -0
- package/src/validator/document-upload-validator.d.ts.map +1 -0
- package/src/validator/email-validator.d.ts.map +1 -0
- package/{types/src → src}/validator/multi-field-input-validator.d.ts +3 -3
- package/src/validator/multi-field-input-validator.d.ts.map +1 -0
- package/src/validator/multi-field-input-validator.js +3 -3
- package/{types/src → src}/validator/numeric-validator.d.ts +2 -2
- package/src/validator/numeric-validator.d.ts.map +1 -0
- package/src/validator/numeric-validator.js +2 -2
- package/src/validator/required-validator.d.ts.map +1 -0
- package/src/validator/same-answer-validator.d.ts.map +1 -0
- package/{types/src → src}/validator/string-validator.d.ts +3 -3
- package/src/validator/string-validator.d.ts.map +1 -0
- package/src/validator/string-validator.js +3 -3
- package/src/validator/unit-option-entry-validator.d.ts.map +1 -0
- package/src/validator/valid-option-validator.d.ts.map +1 -0
- package/src/validator/validation-error-handler.d.ts.map +1 -0
- package/src/validator/validator.d.ts.map +1 -0
- package/test/journey.js +2 -0
- package/test/questions.js +51 -1
- package/test/secondary-actions.test.js +1 -1
- package/test/snapshots/check-your-answers-not-started.html +22 -0
- package/test/snapshots/check-your-answers-with-answers.html +22 -0
- package/test/snapshots/favourite-activity-reason.html +54 -0
- package/test/snapshots/travel-requirements.html +48 -0
- package/test/utils/question-test-utils.js +36 -6
- package/tsconfig.json +11 -4
- package/{types/src/questions → typedefs}/question-props.d.ts +28 -26
- package/typedefs/question-types.d.ts +141 -0
- package/{src → typedefs}/section-types.d.ts +1 -1
- package/typedefs/section-types.js +1 -0
- package/move-types.js +0 -12
- package/src/questions/question-props.d.ts +0 -295
- package/src/questions/question-types.d.ts +0 -86
- package/types/commitlint.config.d.ts +0 -7
- package/types/commitlint.config.d.ts.map +0 -1
- package/types/eslint.config.d.ts +0 -97
- package/types/eslint.config.d.ts.map +0 -1
- package/types/move-types.d.ts +0 -2
- package/types/move-types.d.ts.map +0 -1
- package/types/src/components/address/question.d.ts.map +0 -1
- package/types/src/components/boolean/question.d.ts.map +0 -1
- package/types/src/components/checkbox/question.d.ts +0 -33
- package/types/src/components/checkbox/question.d.ts.map +0 -1
- package/types/src/components/date/question.d.ts.map +0 -1
- package/types/src/components/date-period/question.d.ts.map +0 -1
- package/types/src/components/date-time/question.d.ts.map +0 -1
- package/types/src/components/email/question.d.ts +0 -35
- package/types/src/components/email/question.d.ts.map +0 -1
- package/types/src/components/manage-list/manage-list-actions.d.ts.map +0 -1
- package/types/src/components/manage-list/manage-list-section.d.ts.map +0 -1
- package/types/src/components/manage-list/question.d.ts.map +0 -1
- package/types/src/components/manage-list/utils.d.ts.map +0 -1
- package/types/src/components/multi-field-input/question.d.ts +0 -64
- package/types/src/components/multi-field-input/question.d.ts.map +0 -1
- package/types/src/components/number-entry/question.d.ts +0 -36
- package/types/src/components/number-entry/question.d.ts.map +0 -1
- package/types/src/components/radio/question.d.ts +0 -23
- package/types/src/components/radio/question.d.ts.map +0 -1
- package/types/src/components/select/question.d.ts +0 -22
- package/types/src/components/select/question.d.ts.map +0 -1
- package/types/src/components/single-line-input/question.d.ts.map +0 -1
- package/types/src/components/text-entry/question.d.ts.map +0 -1
- package/types/src/components/text-entry-redact/question.d.ts.map +0 -1
- package/types/src/components/unit-option-entry/question.d.ts.map +0 -1
- package/types/src/components/utils/component-types.d.ts.map +0 -1
- package/types/src/components/utils/persisted-number-answer.d.ts.map +0 -1
- package/types/src/components/utils/question-has-answer.d.ts.map +0 -1
- package/types/src/components/utils/question-utils.d.ts +0 -15
- package/types/src/components/utils/question-utils.d.ts.map +0 -1
- package/types/src/controller.d.ts.map +0 -1
- package/types/src/index.d.ts.map +0 -1
- package/types/src/journey/journey-response.d.ts +0 -32
- package/types/src/journey/journey-response.d.ts.map +0 -1
- package/types/src/journey/journey-types.d.ts +0 -28
- package/types/src/journey/journey-types.d.ts.map +0 -1
- package/types/src/journey/journey.d.ts.map +0 -1
- package/types/src/lib/address-utils.d.ts.map +0 -1
- package/types/src/lib/address.d.ts.map +0 -1
- package/types/src/lib/date-utils.d.ts.map +0 -1
- package/types/src/lib/session-answer-store.d.ts.map +0 -1
- package/types/src/lib/utils.d.ts.map +0 -1
- package/types/src/lib/uuid.d.ts.map +0 -1
- package/types/src/middleware/build-get-journey.d.ts.map +0 -1
- package/types/src/middleware/redirect-to-unanswered-question.d.ts +0 -12
- package/types/src/middleware/redirect-to-unanswered-question.d.ts.map +0 -1
- package/types/src/questions/create-questions.d.ts +0 -18
- package/types/src/questions/create-questions.d.ts.map +0 -1
- package/types/src/questions/options-question.d.ts.map +0 -1
- package/types/src/questions/question-props.d.ts.map +0 -1
- package/types/src/questions/question-types.d.ts +0 -86
- package/types/src/questions/question-types.d.ts.map +0 -1
- package/types/src/questions/question.d.ts.map +0 -1
- package/types/src/questions/questions.d.ts +0 -3
- package/types/src/questions/questions.d.ts.map +0 -1
- package/types/src/section.d.ts.map +0 -1
- package/types/src/validator/address-validator.d.ts.map +0 -1
- package/types/src/validator/base-validator.d.ts.map +0 -1
- package/types/src/validator/conditional-required-validator.d.ts.map +0 -1
- package/types/src/validator/confirmation-checkbox-validator.d.ts.map +0 -1
- package/types/src/validator/coordinates-validator.d.ts.map +0 -1
- package/types/src/validator/cross-question-validator.d.ts.map +0 -1
- package/types/src/validator/date-period-validator.d.ts.map +0 -1
- package/types/src/validator/date-time-validator.d.ts.map +0 -1
- package/types/src/validator/date-validator.d.ts.map +0 -1
- package/types/src/validator/document-upload-validator.d.ts.map +0 -1
- package/types/src/validator/email-validator.d.ts.map +0 -1
- package/types/src/validator/multi-field-input-validator.d.ts.map +0 -1
- package/types/src/validator/numeric-validator.d.ts.map +0 -1
- package/types/src/validator/required-validator.d.ts.map +0 -1
- package/types/src/validator/same-answer-validator.d.ts.map +0 -1
- package/types/src/validator/string-validator.d.ts.map +0 -1
- package/types/src/validator/unit-option-entry-validator.d.ts.map +0 -1
- package/types/src/validator/valid-option-validator.d.ts.map +0 -1
- package/types/src/validator/validation-error-handler.d.ts.map +0 -1
- package/types/src/validator/validator.d.ts.map +0 -1
- /package/{types/src → src}/components/manage-list/manage-list-actions.d.ts +0 -0
- /package/{types/src → src}/components/manage-list/manage-list-section.d.ts +0 -0
- /package/{types/src → src}/components/utils/component-types.d.ts +0 -0
- /package/{types/src → src}/components/utils/persisted-number-answer.d.ts +0 -0
- /package/{types/src → src}/components/utils/question-has-answer.d.ts +0 -0
- /package/{types/src → src}/lib/address-utils.d.ts +0 -0
- /package/{types/src → src}/lib/address.d.ts +0 -0
- /package/{types/src → src}/lib/date-utils.d.ts +0 -0
- /package/{types/src → src}/lib/session-answer-store.d.ts +0 -0
- /package/{types/src → src}/lib/utils.d.ts +0 -0
- /package/{types/src → src}/lib/uuid.d.ts +0 -0
- /package/{types/src → src}/middleware/build-get-journey.d.ts +0 -0
- /package/{types/src → src}/validator/address-validator.d.ts +0 -0
- /package/{types/src → src}/validator/base-validator.d.ts +0 -0
- /package/{types/src → src}/validator/conditional-required-validator.d.ts +0 -0
- /package/{types/src → src}/validator/confirmation-checkbox-validator.d.ts +0 -0
- /package/{types/src → src}/validator/coordinates-validator.d.ts +0 -0
- /package/{types/src → src}/validator/cross-question-validator.d.ts +0 -0
- /package/{types/src → src}/validator/date-period-validator.d.ts +0 -0
- /package/{types/src → src}/validator/date-time-validator.d.ts +0 -0
- /package/{types/src → src}/validator/date-validator.d.ts +0 -0
- /package/{types/src → src}/validator/document-upload-validator.d.ts +0 -0
- /package/{types/src → src}/validator/email-validator.d.ts +0 -0
- /package/{types/src → src}/validator/required-validator.d.ts +0 -0
- /package/{types/src → src}/validator/same-answer-validator.d.ts +0 -0
- /package/{types/src → src}/validator/unit-option-entry-validator.d.ts +0 -0
- /package/{types/src → src}/validator/valid-option-validator.d.ts +0 -0
- /package/{types/src → src}/validator/validation-error-handler.d.ts +0 -0
- /package/{types/src → src}/validator/validator.d.ts +0 -0
- /package/{src/journey → typedefs}/journey-types.d.ts +0 -0
- /package/{src/journey → typedefs}/journey-types.js +0 -0
- /package/{src/questions → typedefs}/question-props.js +0 -0
- /package/{src/questions → typedefs}/question-types.js +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<div class="govuk-grid-row">
|
|
2
|
+
<div class="govuk-grid-column-two-thirds">
|
|
3
|
+
<form action="" method="post" novalidate>
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
<fieldset class="govuk-fieldset">
|
|
7
|
+
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
|
|
8
|
+
<h1 class="govuk-fieldset__heading">
|
|
9
|
+
Why do you want to do your favourite activity?
|
|
10
|
+
</h1>
|
|
11
|
+
</legend>
|
|
12
|
+
|
|
13
|
+
<div class="govuk-form-group">
|
|
14
|
+
<div class="govuk-radios govuk-radios" data-module="govuk-radios">
|
|
15
|
+
<div class="govuk-radios__item">
|
|
16
|
+
<input class="govuk-radios__input" id="favouriteActivityReason" name="favouriteActivityReason" type="radio" value="relaxation" data-aria-controls="conditional-favouriteActivityReason" data-cy="answer-relaxation">
|
|
17
|
+
<label class="govuk-label govuk-radios__label" for="favouriteActivityReason">
|
|
18
|
+
Relaxation
|
|
19
|
+
</label>
|
|
20
|
+
</div>
|
|
21
|
+
<div class="govuk-radios__conditional govuk-radios__conditional--hidden" id="conditional-favouriteActivityReason">
|
|
22
|
+
<div class="govuk-form-group">
|
|
23
|
+
<label class="govuk-label" for="favouriteActivityReason_relaxationDetails">
|
|
24
|
+
How do you like to relax?
|
|
25
|
+
</label>
|
|
26
|
+
<input class="govuk-input" id="favouriteActivityReason_relaxationDetails" name="favouriteActivityReason_relaxationDetails" type="text" value="">
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="govuk-radios__item">
|
|
30
|
+
<input class="govuk-radios__input" id="favouriteActivityReason-2" name="favouriteActivityReason" type="radio" value="adventure" data-cy="answer-adventure">
|
|
31
|
+
<label class="govuk-label govuk-radios__label" for="favouriteActivityReason-2">
|
|
32
|
+
Adventure
|
|
33
|
+
</label>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="govuk-radios__item">
|
|
36
|
+
<input class="govuk-radios__input" id="favouriteActivityReason-3" name="favouriteActivityReason" type="radio" value="culture" data-cy="answer-culture">
|
|
37
|
+
<label class="govuk-label govuk-radios__label" for="favouriteActivityReason-3">
|
|
38
|
+
Culture
|
|
39
|
+
</label>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
</fieldset>
|
|
47
|
+
|
|
48
|
+
<button type="submit" class="govuk-button" data-module="govuk-button" data-cy="button-save-and-continue">
|
|
49
|
+
Continue
|
|
50
|
+
</button>
|
|
51
|
+
|
|
52
|
+
</form>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<div class="govuk-grid-row">
|
|
2
|
+
<div class="govuk-grid-column-two-thirds">
|
|
3
|
+
<form action="" method="post" novalidate>
|
|
4
|
+
<div class="govuk-form-group">
|
|
5
|
+
<fieldset class="govuk-fieldset">
|
|
6
|
+
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
|
|
7
|
+
<h1 class="govuk-fieldset__heading">
|
|
8
|
+
What special requirements do you have?
|
|
9
|
+
</h1>
|
|
10
|
+
</legend>
|
|
11
|
+
<div class="govuk-checkboxes govuk-checkboxes" data-module="govuk-checkboxes">
|
|
12
|
+
<div class="govuk-checkboxes__item">
|
|
13
|
+
<input class="govuk-checkboxes__input" id="travelRequirements" name="travelRequirements" type="checkbox" value="dietary" data-aria-controls="conditional-travelRequirements" data-cy="answer-dietary">
|
|
14
|
+
<label class="govuk-label govuk-checkboxes__label" for="travelRequirements">
|
|
15
|
+
Dietary requirements
|
|
16
|
+
</label>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" id="conditional-travelRequirements">
|
|
19
|
+
<div class="govuk-form-group">
|
|
20
|
+
<label class="govuk-label" for="travelRequirements_dietaryDetails">
|
|
21
|
+
Please describe your dietary requirements
|
|
22
|
+
</label>
|
|
23
|
+
<input class="govuk-input" id="travelRequirements_dietaryDetails" name="travelRequirements_dietaryDetails" type="text" value="">
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
<div class="govuk-checkboxes__item">
|
|
27
|
+
<input class="govuk-checkboxes__input" id="travelRequirements-2" name="travelRequirements" type="checkbox" value="mobility" data-cy="answer-mobility">
|
|
28
|
+
<label class="govuk-label govuk-checkboxes__label" for="travelRequirements-2">
|
|
29
|
+
Mobility assistance
|
|
30
|
+
</label>
|
|
31
|
+
</div>
|
|
32
|
+
<div class="govuk-checkboxes__item">
|
|
33
|
+
<input class="govuk-checkboxes__input" id="travelRequirements-3" name="travelRequirements" type="checkbox" value="medical" data-cy="answer-medical">
|
|
34
|
+
<label class="govuk-label govuk-checkboxes__label" for="travelRequirements-3">
|
|
35
|
+
Medical needs
|
|
36
|
+
</label>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
</fieldset>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<button type="submit" class="govuk-button" data-module="govuk-button" data-cy="button-save-and-continue">
|
|
43
|
+
Continue
|
|
44
|
+
</button>
|
|
45
|
+
|
|
46
|
+
</form>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
@@ -101,9 +101,24 @@ export function mockAnswerBody(q) {
|
|
|
101
101
|
switch (q.type) {
|
|
102
102
|
case COMPONENT_TYPES.BOOLEAN:
|
|
103
103
|
return { [q.fieldName]: BOOLEAN_OPTIONS.YES };
|
|
104
|
-
case COMPONENT_TYPES.CHECKBOX:
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
case COMPONENT_TYPES.CHECKBOX: {
|
|
105
|
+
const result = { [q.fieldName]: [q.options[0].value] };
|
|
106
|
+
// Include conditional field if present on the first option
|
|
107
|
+
if (q.options[0].conditional?.fieldName) {
|
|
108
|
+
const conditionalFieldName = `${q.fieldName}_${q.options[0].conditional.fieldName}`;
|
|
109
|
+
result[conditionalFieldName] = 'test conditional answer';
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
case COMPONENT_TYPES.RADIO: {
|
|
114
|
+
const result = { [q.fieldName]: q.options[0].value };
|
|
115
|
+
// Include conditional field if present on the first option
|
|
116
|
+
if (q.options[0].conditional?.fieldName) {
|
|
117
|
+
const conditionalFieldName = `${q.fieldName}_${q.options[0].conditional.fieldName}`;
|
|
118
|
+
result[conditionalFieldName] = 'test conditional answer';
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
107
122
|
case COMPONENT_TYPES.SELECT:
|
|
108
123
|
return { [q.fieldName]: q.options[0].value };
|
|
109
124
|
case COMPONENT_TYPES.NUMBER:
|
|
@@ -181,9 +196,24 @@ export function mockAnswer(q) {
|
|
|
181
196
|
switch (q.type) {
|
|
182
197
|
case COMPONENT_TYPES.BOOLEAN:
|
|
183
198
|
return BOOLEAN_OPTIONS.YES;
|
|
184
|
-
case COMPONENT_TYPES.CHECKBOX:
|
|
185
|
-
|
|
186
|
-
|
|
199
|
+
case COMPONENT_TYPES.CHECKBOX: {
|
|
200
|
+
const optionText = q.options[0].text;
|
|
201
|
+
// Include conditional value if present on the first option
|
|
202
|
+
if (q.options[0].conditional?.fieldName) {
|
|
203
|
+
const label = q.options[0].conditional.label ? `${q.options[0].conditional.label} ` : '';
|
|
204
|
+
return `${optionText}<br>${label}test conditional answer`;
|
|
205
|
+
}
|
|
206
|
+
return optionText;
|
|
207
|
+
}
|
|
208
|
+
case COMPONENT_TYPES.RADIO: {
|
|
209
|
+
const optionText = q.options[0].text;
|
|
210
|
+
// Include conditional value if present on the first option
|
|
211
|
+
if (q.options[0].conditional?.fieldName) {
|
|
212
|
+
const label = q.options[0].conditional.label ? `${q.options[0].conditional.label} ` : '';
|
|
213
|
+
return `${optionText}<br>${label}test conditional answer`;
|
|
214
|
+
}
|
|
215
|
+
return optionText;
|
|
216
|
+
}
|
|
187
217
|
case COMPONENT_TYPES.SELECT:
|
|
188
218
|
return q.options[0].text;
|
|
189
219
|
case COMPONENT_TYPES.NUMBER:
|
package/tsconfig.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"include": ["**/*.ts", "**/*.js"],
|
|
3
|
-
"exclude": [
|
|
3
|
+
"exclude": [
|
|
4
|
+
"node_modules",
|
|
5
|
+
"packages/database/src/client/**",
|
|
6
|
+
"**/*.test.ts",
|
|
7
|
+
"**/*.test.js",
|
|
8
|
+
"test/**",
|
|
9
|
+
"*.config.js",
|
|
10
|
+
"typedefs/**"
|
|
11
|
+
],
|
|
4
12
|
"compilerOptions": {
|
|
5
13
|
"allowImportingTsExtensions": true,
|
|
6
14
|
"allowJs": true,
|
|
@@ -14,13 +22,12 @@
|
|
|
14
22
|
"esModuleInterop": true,
|
|
15
23
|
"module": "NodeNext",
|
|
16
24
|
"moduleResolution": "nodenext",
|
|
17
|
-
"outDir": "types",
|
|
18
|
-
"rootDir": ".",
|
|
19
25
|
"strict": true,
|
|
20
26
|
"target": "esnext",
|
|
21
27
|
"skipLibCheck": true,
|
|
22
28
|
"paths": {
|
|
23
|
-
"#question-types": ["./
|
|
29
|
+
"#question-types": ["./typedefs/question-types.d.ts"],
|
|
30
|
+
"#typedefs/*": ["./typedefs/*"],
|
|
24
31
|
"#src/*": ["./src/*"],
|
|
25
32
|
"#test/*": ["./test/*"],
|
|
26
33
|
"#question": ["./src/questions/question.js"],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { QuestionParameters } from '
|
|
1
|
+
import type { QuestionParameters } from './question-types.d.ts';
|
|
2
2
|
|
|
3
|
-
type QuestionTypes =
|
|
3
|
+
export type QuestionTypes =
|
|
4
4
|
| 'boolean'
|
|
5
5
|
| 'checkbox'
|
|
6
6
|
| 'date'
|
|
@@ -26,7 +26,7 @@ export type CommonQuestionParams = Omit<QuestionParameters, 'viewFolder'>;
|
|
|
26
26
|
/**
|
|
27
27
|
* Full props including type for routing/factory layer
|
|
28
28
|
*/
|
|
29
|
-
type CommonQuestionProps = CommonQuestionParams & {
|
|
29
|
+
export type CommonQuestionProps = CommonQuestionParams & {
|
|
30
30
|
type: QuestionTypes;
|
|
31
31
|
};
|
|
32
32
|
|
|
@@ -37,29 +37,31 @@ export type BaseQuestionProps = CommonQuestionParams & {
|
|
|
37
37
|
type: string;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
type
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
40
|
+
export type SelectableOption = {
|
|
41
|
+
text: string;
|
|
42
|
+
value: string;
|
|
43
|
+
hint?: object;
|
|
44
|
+
checked?: boolean | undefined;
|
|
45
|
+
attributes?: Record<string, string>;
|
|
46
|
+
behaviour?: 'exclusive';
|
|
47
|
+
conditional?: {
|
|
48
|
+
question: string;
|
|
49
|
+
type: string;
|
|
50
|
+
fieldName: string;
|
|
51
|
+
inputClasses?: string;
|
|
52
|
+
html?: string;
|
|
53
|
+
value?: unknown;
|
|
54
|
+
label?: string;
|
|
55
|
+
hint?: string;
|
|
56
|
+
};
|
|
57
|
+
conditionalText?: {
|
|
58
|
+
html: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type DividerOption = { divider?: string };
|
|
63
|
+
|
|
64
|
+
export type Option = SelectableOption | DividerOption;
|
|
63
65
|
|
|
64
66
|
type Affix = {
|
|
65
67
|
text: string;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { RouteParams } from './journey-types.d.ts';
|
|
2
|
+
import type ManageListQuestion from '#src/components/manage-list/question.js';
|
|
3
|
+
import type BaseValidator from '#src/validator/base-validator.js';
|
|
4
|
+
import type { JourneyResponse } from '#src/journey/journey-response.js';
|
|
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
|
+
export interface QuestionParameters {
|
|
30
|
+
title: string;
|
|
31
|
+
question: string;
|
|
32
|
+
viewFolder: string;
|
|
33
|
+
fieldName: string;
|
|
34
|
+
url?: string;
|
|
35
|
+
pageTitle?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
validators?: BaseValidator[];
|
|
38
|
+
html?: string;
|
|
39
|
+
hint?: string;
|
|
40
|
+
interfaceType?: string;
|
|
41
|
+
shouldDisplay?: (response: JourneyResponse) => boolean;
|
|
42
|
+
autocomplete?: string;
|
|
43
|
+
// is this question editable? defaults to true
|
|
44
|
+
editable?: boolean;
|
|
45
|
+
// override the action link for this question
|
|
46
|
+
actionLink?: ActionLink;
|
|
47
|
+
// custom function to format the summary display value
|
|
48
|
+
formatSummaryValue?: SummaryValueFormatter;
|
|
49
|
+
// whether to capitalise the first letter of the answer in summary (defaults to true)
|
|
50
|
+
capitaliseAnswer?: boolean;
|
|
51
|
+
// static view data for this question
|
|
52
|
+
viewData?: {
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated replaced by secondaryActions
|
|
55
|
+
*/
|
|
56
|
+
extraActionButtons?: SecondaryAction[];
|
|
57
|
+
/**
|
|
58
|
+
* Secondary action buttons
|
|
59
|
+
*/
|
|
60
|
+
secondaryActions?: SecondaryAction[];
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ActionLink {
|
|
66
|
+
text: string;
|
|
67
|
+
href: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type SecondaryAction = SecondaryActionButton | SecondaryActionLink;
|
|
71
|
+
|
|
72
|
+
export interface SecondaryActionButton {
|
|
73
|
+
text: string;
|
|
74
|
+
type?: string;
|
|
75
|
+
formaction?: string;
|
|
76
|
+
classes?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface SecondaryActionLink {
|
|
80
|
+
text: string;
|
|
81
|
+
href: string;
|
|
82
|
+
classes?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface BaseQuestionViewData {
|
|
86
|
+
value: unknown;
|
|
87
|
+
question: string;
|
|
88
|
+
fieldName: string;
|
|
89
|
+
pageTitle: string;
|
|
90
|
+
description?: string;
|
|
91
|
+
html?: string;
|
|
92
|
+
hint?: string;
|
|
93
|
+
interfaceType?: string;
|
|
94
|
+
autocomplete?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface QuestionViewModel<TQuestionViewData extends BaseQuestionViewData = BaseQuestionViewData> {
|
|
98
|
+
question: TQuestionViewData;
|
|
99
|
+
answer: unknown;
|
|
100
|
+
layoutTemplate: string;
|
|
101
|
+
pageCaption?: string;
|
|
102
|
+
continueButtonText: string;
|
|
103
|
+
backLink?: string;
|
|
104
|
+
showBackToListLink: boolean;
|
|
105
|
+
listLink: string;
|
|
106
|
+
journeyTitle: string;
|
|
107
|
+
payload?: unknown;
|
|
108
|
+
util: {
|
|
109
|
+
trimTrailingSlash: (str: string) => string;
|
|
110
|
+
};
|
|
111
|
+
[key: string]: unknown;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface PrepQuestionForRenderingOptions {
|
|
115
|
+
params: RouteParams;
|
|
116
|
+
manageListQuestion?: ManageListQuestion;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Define a question class type so that projects downstream can extend the
|
|
121
|
+
* Question class and still pass them to the createQuestions function.
|
|
122
|
+
*/
|
|
123
|
+
export type QuestionClass<TQuestion extends Question = Question> = new (...args: never[]) => TQuestion;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Action link displayed in summary lists
|
|
127
|
+
*/
|
|
128
|
+
export interface ActionView {
|
|
129
|
+
href: string;
|
|
130
|
+
text: string;
|
|
131
|
+
visuallyHiddenText?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A row in a summary list, returned by formatAnswerForSummary
|
|
136
|
+
*/
|
|
137
|
+
export interface SummaryRow {
|
|
138
|
+
key: string;
|
|
139
|
+
value: string;
|
|
140
|
+
action?: ActionView | ActionView[];
|
|
141
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JourneyResponse } from '#src/journey/journey-response.js';
|
|
2
2
|
import ManageListQuestion from '#src/components/manage-list/question.js';
|
|
3
3
|
import { Question } from '#src/questions/question.js';
|
|
4
|
-
import { RouteParams } from '
|
|
4
|
+
import { RouteParams } from './journey-types.d.ts';
|
|
5
5
|
|
|
6
6
|
export interface GetNextQuestionParams {
|
|
7
7
|
questionFieldName: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// empty source file to go with .d.ts file
|
package/move-types.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { copyFile } from 'node:fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const filesToCopy = ['questions/question-props.d.ts', 'questions/question-types.d.ts', 'journey/journey-types.d.ts'];
|
|
5
|
-
|
|
6
|
-
// copy some of the type definition files to the types output that are not automatically included
|
|
7
|
-
for (const file of filesToCopy) {
|
|
8
|
-
const src = path.join(import.meta.dirname, 'src', file);
|
|
9
|
-
const dest = path.join(import.meta.dirname, 'types', 'src', file);
|
|
10
|
-
await copyFile(src, dest);
|
|
11
|
-
console.log(`Copied ${src} to ${dest}`);
|
|
12
|
-
}
|