@planning-inspectorate/dynamic-forms 3.15.3 → 3.15.5
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 +1 -1
- package/src/components/manage-list/manage-list-section.js +1 -1
- package/src/components/multi-field-input/index.njk +2 -0
- package/src/questions/question-props.d.ts +2 -0
- package/src/section.js +4 -4
- package/test/questions.js +2 -2
- package/test/snapshots/companions.html +1 -1
- package/test/utils/question-test-utils.js +14 -2
- package/types/src/components/manage-list/manage-list-section.d.ts +1 -1
- package/types/src/components/manage-list/manage-list-section.d.ts.map +1 -1
- package/types/src/components/multi-field-input/question.d.ts +2 -0
- package/types/src/components/multi-field-input/question.d.ts.map +1 -1
- package/types/src/questions/question-props.d.ts +2 -0
- package/types/src/section.d.ts +8 -8
- package/types/src/section.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -77,6 +77,8 @@ interface InputField {
|
|
|
77
77
|
prefix?: Affix; // used to add a prefix to the field
|
|
78
78
|
hint?: string;
|
|
79
79
|
classes?: string;
|
|
80
|
+
inputmode?: 'decimal' | 'numeric';
|
|
81
|
+
pattern?: string; // Used for backwards-compatibility for older iOS devices in numeric input fields
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/*
|
package/src/section.js
CHANGED
|
@@ -65,7 +65,7 @@ export class Section {
|
|
|
65
65
|
* Add a condition to all questions in this section
|
|
66
66
|
*
|
|
67
67
|
* @param {QuestionCondition} shouldIncludeSection
|
|
68
|
-
* @returns {
|
|
68
|
+
* @returns {this}
|
|
69
69
|
*/
|
|
70
70
|
withSectionCondition(shouldIncludeSection) {
|
|
71
71
|
if (this.questions.length > 0) {
|
|
@@ -134,7 +134,7 @@ export class Section {
|
|
|
134
134
|
/**
|
|
135
135
|
* Fluent API method for attaching conditions to the previously added question
|
|
136
136
|
* @param {QuestionCondition} shouldIncludeQuestion
|
|
137
|
-
* @returns {
|
|
137
|
+
* @returns {this}
|
|
138
138
|
*/
|
|
139
139
|
withCondition(shouldIncludeQuestion) {
|
|
140
140
|
if (this.#conditionAdded) {
|
|
@@ -175,7 +175,7 @@ export class Section {
|
|
|
175
175
|
* Fluent API method for starting a multi question condition
|
|
176
176
|
* @param {string} conditionName
|
|
177
177
|
* @param {QuestionCondition} shouldIncludeQuestion
|
|
178
|
-
* @returns {
|
|
178
|
+
* @returns {this}
|
|
179
179
|
*/
|
|
180
180
|
startMultiQuestionCondition(conditionName, shouldIncludeQuestion) {
|
|
181
181
|
if (this.#multiQuestionConditions[conditionName]) {
|
|
@@ -188,7 +188,7 @@ export class Section {
|
|
|
188
188
|
/**
|
|
189
189
|
* Fluent API method for ending a multi question condition
|
|
190
190
|
* @param {string} conditionName
|
|
191
|
-
* @returns {
|
|
191
|
+
* @returns {this}
|
|
192
192
|
*/
|
|
193
193
|
endMultiQuestionCondition(conditionName) {
|
|
194
194
|
if (!this.#multiQuestionConditions[conditionName]) {
|
package/test/questions.js
CHANGED
|
@@ -125,8 +125,8 @@ export const questionProps = {
|
|
|
125
125
|
url: 'companions',
|
|
126
126
|
label: 'Companions',
|
|
127
127
|
inputFields: [
|
|
128
|
-
{ fieldName: 'name', label: 'Name'
|
|
129
|
-
{ fieldName: 'age', label: 'Age',
|
|
128
|
+
{ fieldName: 'name', label: 'Name' },
|
|
129
|
+
{ fieldName: 'age', label: 'Age', inputmode: 'numeric', pattern: '[0-9]*' }
|
|
130
130
|
]
|
|
131
131
|
},
|
|
132
132
|
nights: {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<label class="govuk-label govuk-label" for="age">
|
|
23
23
|
Age
|
|
24
24
|
</label>
|
|
25
|
-
<input class="govuk-input govuk-input-!-width-three-quarters" id="age" name="age" type="text">
|
|
25
|
+
<input class="govuk-input govuk-input-!-width-three-quarters" id="age" name="age" type="text" pattern="[0-9]*" inputmode="numeric">
|
|
26
26
|
</div>
|
|
27
27
|
|
|
28
28
|
|
|
@@ -80,6 +80,18 @@ export async function createAppWithQuestions(ctx, options) {
|
|
|
80
80
|
return server;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Returns a mock value for an input field based on its properties.
|
|
85
|
+
* @param {Object} field - An input field descriptor (not a full question)
|
|
86
|
+
* @returns {string|number}
|
|
87
|
+
*/
|
|
88
|
+
function mockInputFieldValue(field) {
|
|
89
|
+
if (field.inputmode === 'numeric' || field.pattern === '[0-9]*') {
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
return 'test';
|
|
93
|
+
}
|
|
94
|
+
|
|
83
95
|
/**
|
|
84
96
|
* Build a valid payload for a question.
|
|
85
97
|
* @param {import('../src/questions/question-props.js').QuestionProps} q
|
|
@@ -128,7 +140,7 @@ export function mockAnswerBody(q) {
|
|
|
128
140
|
case COMPONENT_TYPES.MULTI_FIELD_INPUT: {
|
|
129
141
|
const res = {};
|
|
130
142
|
for (const field of q.inputFields) {
|
|
131
|
-
res[field.fieldName] =
|
|
143
|
+
res[field.fieldName] = mockInputFieldValue(field);
|
|
132
144
|
}
|
|
133
145
|
return res;
|
|
134
146
|
}
|
|
@@ -191,7 +203,7 @@ export function mockAnswer(q) {
|
|
|
191
203
|
if (q.inputFields) {
|
|
192
204
|
let res = '';
|
|
193
205
|
for (const field of q.inputFields) {
|
|
194
|
-
res +=
|
|
206
|
+
res += mockInputFieldValue(field) + '<br>';
|
|
195
207
|
}
|
|
196
208
|
return res;
|
|
197
209
|
}
|
|
@@ -19,5 +19,5 @@ export class ManageListSection extends Section {
|
|
|
19
19
|
*/
|
|
20
20
|
addQuestion(question: import("../../questions/question.js").Question, manageListSection?: import("./manage-list-section.js").ManageListSection): this;
|
|
21
21
|
}
|
|
22
|
-
import { Section } from '
|
|
22
|
+
import { Section } from '../../section.js';
|
|
23
23
|
//# sourceMappingURL=manage-list-section.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manage-list-section.d.ts","sourceRoot":"","sources":["../../../../src/components/manage-list/manage-list-section.js"],"names":[],"mappings":"AAEA;;GAEG;AACH;IACC,cAEC;IAED;;;;;;OAMG;IACH,2BAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,sBAJW,OAAO,6BAA6B,EAAE,QAAQ,sBAC9C,OAAO,0BAA0B,EAAE,iBAAiB,GAClD,IAAI,CAYhB;CACD;wBAtCuB,
|
|
1
|
+
{"version":3,"file":"manage-list-section.d.ts","sourceRoot":"","sources":["../../../../src/components/manage-list/manage-list-section.js"],"names":[],"mappings":"AAEA;;GAEG;AACH;IACC,cAEC;IAED;;;;;;OAMG;IACH,2BAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,sBAJW,OAAO,6BAA6B,EAAE,QAAQ,sBAC9C,OAAO,0BAA0B,EAAE,iBAAiB,GAClD,IAAI,CAYhB;CACD;wBAtCuB,kBAAkB"}
|
|
@@ -26,6 +26,8 @@ export class MultiFieldInputQuestion extends Question {
|
|
|
26
26
|
prefix?: import("../../questions/question-props.d.ts").Affix;
|
|
27
27
|
hint?: string;
|
|
28
28
|
classes?: string;
|
|
29
|
+
inputmode?: "decimal" | "numeric";
|
|
30
|
+
pattern?: string;
|
|
29
31
|
}[];
|
|
30
32
|
/**
|
|
31
33
|
* returns the formatted answers values to be used to build task list elements
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/multi-field-input/question.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH;;GAEG;AACH;IACC;;OAEG;IACH,8CAFW,OAAO,qCAAqC,EAAE,6BAA6B,EAarF;IAJC,wEAA8B;IAchC
|
|
1
|
+
{"version":3,"file":"question.d.ts","sourceRoot":"","sources":["../../../../src/components/multi-field-input/question.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH;;GAEG;AACH;IACC;;OAEG;IACH,8CAFW,OAAO,qCAAqC,EAAE,6BAA6B,EAarF;IAJC,wEAA8B;IAchC;;;;;;;;;;;;;;QAOC;IAsBD;;;;;;;;;;;;;OAaG;IACH,wDAZW,OAAO,GAEL,KAAK,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,EAAE,MAAM,CAAC;YACb,kBAAkB,EAAE,MAAM,CAAC;SAC5B,CAAC;KACH,CAAC,CAkBJ;;CAyBD;;gCAvHY,OAAO,WAAW,EAAE,iBAAiB;sBACrC,OAAO,UAAU,EAAE,OAAO;8BAC1B,OAAO,mBAAmB,EAAE,eAAe;;;yBAP/B,WAAW"}
|
|
@@ -77,6 +77,8 @@ interface InputField {
|
|
|
77
77
|
prefix?: Affix; // used to add a prefix to the field
|
|
78
78
|
hint?: string;
|
|
79
79
|
classes?: string;
|
|
80
|
+
inputmode?: 'decimal' | 'numeric';
|
|
81
|
+
pattern?: string; // Used for backwards-compatibility for older iOS devices in numeric input fields
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/*
|
package/types/src/section.d.ts
CHANGED
|
@@ -38,9 +38,9 @@ export class Section {
|
|
|
38
38
|
* Add a condition to all questions in this section
|
|
39
39
|
*
|
|
40
40
|
* @param {QuestionCondition} shouldIncludeSection
|
|
41
|
-
* @returns {
|
|
41
|
+
* @returns {this}
|
|
42
42
|
*/
|
|
43
|
-
withSectionCondition(shouldIncludeSection: QuestionCondition):
|
|
43
|
+
withSectionCondition(shouldIncludeSection: QuestionCondition): this;
|
|
44
44
|
/**
|
|
45
45
|
* Fluent API method for adding questions
|
|
46
46
|
* @param {import('./questions/question.js').Question} question
|
|
@@ -51,23 +51,23 @@ export class Section {
|
|
|
51
51
|
/**
|
|
52
52
|
* Fluent API method for attaching conditions to the previously added question
|
|
53
53
|
* @param {QuestionCondition} shouldIncludeQuestion
|
|
54
|
-
* @returns {
|
|
54
|
+
* @returns {this}
|
|
55
55
|
*/
|
|
56
|
-
withCondition(shouldIncludeQuestion: QuestionCondition):
|
|
56
|
+
withCondition(shouldIncludeQuestion: QuestionCondition): this;
|
|
57
57
|
withRequiredCondition(isQuestionMandatory: any, requiredFieldErrorMsg: any): this;
|
|
58
58
|
/**
|
|
59
59
|
* Fluent API method for starting a multi question condition
|
|
60
60
|
* @param {string} conditionName
|
|
61
61
|
* @param {QuestionCondition} shouldIncludeQuestion
|
|
62
|
-
* @returns {
|
|
62
|
+
* @returns {this}
|
|
63
63
|
*/
|
|
64
|
-
startMultiQuestionCondition(conditionName: string, shouldIncludeQuestion: QuestionCondition):
|
|
64
|
+
startMultiQuestionCondition(conditionName: string, shouldIncludeQuestion: QuestionCondition): this;
|
|
65
65
|
/**
|
|
66
66
|
* Fluent API method for ending a multi question condition
|
|
67
67
|
* @param {string} conditionName
|
|
68
|
-
* @returns {
|
|
68
|
+
* @returns {this}
|
|
69
69
|
*/
|
|
70
|
-
endMultiQuestionCondition(conditionName: string):
|
|
70
|
+
endMultiQuestionCondition(conditionName: string): this;
|
|
71
71
|
/**
|
|
72
72
|
* Get the next question in this section given a questionParam (question fieldName)
|
|
73
73
|
* @param {import('./section-types.d.ts').GetNextQuestionParams} params
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../../src/section.js"],"names":[],"mappings":"AASA;;;;GAIG;AACH,6BAFU,MAAM,CAEuC;AAEvD;;;GAGG;AACH;IAgNC;;;;;OAKG;IACH,8FAHW,OAAO,sBAAsB,EAAE,2BAA2B,GACxD,QAAQ,GAAC,MAAM,GAAC,IAAI,CAoBhC;IAvMD;;;;OAIG;IACH,kBAHW,MAAM,WACN,MAAM,EAKhB;IAxCD;;OAEG;IACH,MAFU,MAAM,CAEX;IAEL;;OAEG;IACH,SAFU,MAAM,CAER;IAER;;OAEG;IACH,WAFU,KAAK,CAAC,QAAQ,CAAC,CAEV;IA6Bf;;;;;OAKG;IACH,2CAHW,iBAAiB,GACf,
|
|
1
|
+
{"version":3,"file":"section.d.ts","sourceRoot":"","sources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