@planning-inspectorate/dynamic-forms 3.3.2 → 3.3.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Question } from '#question';
|
|
2
2
|
import { Uuid } from '#src/lib/uuid.js';
|
|
3
|
-
import
|
|
3
|
+
import nunjucks from 'nunjucks';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef {Object} ManageListQuestionParameters
|
|
@@ -107,7 +107,10 @@ export default class ManageListQuestion extends Question {
|
|
|
107
107
|
if (answer && Array.isArray(answer)) {
|
|
108
108
|
if (this.#showAnswersInSummary) {
|
|
109
109
|
const answers = answer.map((a) => this.#formatItemAnswers(a));
|
|
110
|
-
|
|
110
|
+
// note: nunjucks.render uses the last configured environment
|
|
111
|
+
// so we assume here that it is the one used by the main application and
|
|
112
|
+
// is configured for dynamic-forms and govuk components
|
|
113
|
+
formattedAnswer = nunjucks.render('components/manage-list/answer-summary-list.njk', { answers });
|
|
111
114
|
} else if (answer.length > 0) {
|
|
112
115
|
formattedAnswer = `${answer.length} ${this.title}`;
|
|
113
116
|
}
|
|
@@ -91,6 +91,8 @@ describe('components/manage-list/question', () => {
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
it('should support showing all answers in the format list answer for summary', (ctx) => {
|
|
94
|
+
// nunjucks.render uses the last environment configured, so make sure one is configured
|
|
95
|
+
configureNunjucksTestEnv();
|
|
94
96
|
const { q } = questionWithManageQuestions(ctx, { showAnswersInSummary: true });
|
|
95
97
|
const answerForSummary = q.formatAnswerForSummary('section-1', mockJourney(), [{}, {}, {}]);
|
|
96
98
|
assert.strictEqual(answerForSummary.length, 1);
|
|
@@ -112,6 +112,9 @@ export default class UnitOptionEntryQuestion extends Question {
|
|
|
112
112
|
conditionalField.value = payload ? payload[conditionalField.fieldName] : existingValue;
|
|
113
113
|
|
|
114
114
|
optionData.conditional = {
|
|
115
|
+
// note: nunjucks.render uses the last configured environment
|
|
116
|
+
// so we assume here that it is the one used by the main application and
|
|
117
|
+
// is configured for dynamic-forms and govuk components
|
|
115
118
|
html: nunjucks.render(`./components/conditional/unit.njk`, {
|
|
116
119
|
payload,
|
|
117
120
|
...conditionalField,
|
|
@@ -100,6 +100,9 @@ export default class OptionsQuestion extends Question {
|
|
|
100
100
|
conditionalField.value = answers[conditionalField.fieldName] || '';
|
|
101
101
|
|
|
102
102
|
optionData.conditional = {
|
|
103
|
+
// note: nunjucks.render uses the last configured environment
|
|
104
|
+
// so we assume here that it is the one used by the main application and
|
|
105
|
+
// is configured for dynamic-forms and govuk components
|
|
103
106
|
html: nunjucks.render(`./components/conditional/${conditionalField.type}.njk`, {
|
|
104
107
|
payload,
|
|
105
108
|
...conditionalField,
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import nunjucks from 'nunjucks';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns a nunjucks environment configured with the `src` folder
|
|
6
|
-
* @returns {import('nunjucks').Environment}
|
|
7
|
-
*/
|
|
8
|
-
export function nunjucksEnv() {
|
|
9
|
-
const utilsDir = path.dirname(new URL(import.meta.url).pathname);
|
|
10
|
-
const srcDir = path.resolve(utilsDir, '..', '..');
|
|
11
|
-
|
|
12
|
-
return nunjucks.configure([srcDir], {
|
|
13
|
-
// output with dangerous characters are escaped automatically
|
|
14
|
-
autoescape: true,
|
|
15
|
-
// automatically remove trailing newlines from a block/tag
|
|
16
|
-
trimBlocks: true,
|
|
17
|
-
// automatically remove leading whitespace from a block/tag
|
|
18
|
-
lstripBlocks: true
|
|
19
|
-
});
|
|
20
|
-
}
|