@defra/forms-model 3.0.566 → 3.0.568
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/dist/module/form/form-definition/helpers.js +12 -0
- package/dist/module/form/form-definition/helpers.js.map +1 -0
- package/dist/module/form/form-definition/index.js +31 -2
- package/dist/module/form/form-definition/index.js.map +1 -1
- package/dist/module/form/form-editor/__stubs__/preview.js +128 -1
- package/dist/module/form/form-editor/__stubs__/preview.js.map +1 -1
- package/dist/module/form/form-editor/index.js +1 -1
- package/dist/module/form/form-editor/index.js.map +1 -1
- package/dist/module/form/form-editor/macros/types.js.map +1 -1
- package/dist/module/form/form-editor/preview/component-elements.js +1 -0
- package/dist/module/form/form-editor/preview/component-elements.js.map +1 -1
- package/dist/module/form/form-editor/preview/helpers.js +3 -1
- package/dist/module/form/form-editor/preview/helpers.js.map +1 -1
- package/dist/module/form/form-editor/preview/number-only.js +75 -3
- package/dist/module/form/form-editor/preview/number-only.js.map +1 -1
- package/dist/module/form/form-editor/preview/question.js +30 -3
- package/dist/module/form/form-editor/preview/question.js.map +1 -1
- package/dist/module/form/form-editor/preview/types.js.map +1 -1
- package/dist/module/form/form-manager/errors.js +23 -0
- package/dist/module/form/form-manager/errors.js.map +1 -1
- package/dist/module/form/form-manager/types.js +6 -0
- package/dist/module/form/form-manager/types.js.map +1 -1
- package/dist/module/index.js +1 -0
- package/dist/module/index.js.map +1 -1
- package/dist/types/form/form-definition/helpers.d.ts +8 -0
- package/dist/types/form/form-definition/helpers.d.ts.map +1 -0
- package/dist/types/form/form-definition/index.d.ts.map +1 -1
- package/dist/types/form/form-editor/__stubs__/preview.d.ts +71 -1
- package/dist/types/form/form-editor/__stubs__/preview.d.ts.map +1 -1
- package/dist/types/form/form-editor/index.d.ts.map +1 -1
- package/dist/types/form/form-editor/macros/types.d.ts +7 -0
- package/dist/types/form/form-editor/macros/types.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/component-elements.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/helpers.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/number-only.d.ts +123 -0
- package/dist/types/form/form-editor/preview/number-only.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/question.d.ts +13 -0
- package/dist/types/form/form-editor/preview/question.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/types.d.ts +8 -0
- package/dist/types/form/form-editor/preview/types.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/uk-address.d.ts +7 -0
- package/dist/types/form/form-editor/preview/uk-address.d.ts.map +1 -1
- package/dist/types/form/form-manager/errors.d.ts.map +1 -1
- package/dist/types/form/form-manager/types.d.ts +17 -1
- package/dist/types/form/form-manager/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/form/form-definition/helpers.ts +17 -0
- package/src/form/form-definition/index.ts +53 -3
- package/src/form/form-editor/__stubs__/preview.js +130 -1
- package/src/form/form-editor/index.ts +4 -1
- package/src/form/form-editor/macros/types.ts +3 -0
- package/src/form/form-editor/preview/component-elements.js +4 -0
- package/src/form/form-editor/preview/helpers.js +6 -1
- package/src/form/form-editor/preview/number-only.js +72 -3
- package/src/form/form-editor/preview/question.js +33 -3
- package/src/form/form-editor/preview/types.ts +10 -0
- package/src/form/form-manager/errors.ts +30 -0
- package/src/form/form-manager/types.ts +23 -1
- package/src/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uk-address.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/uk-address.js"],"names":[],"mappings":"AAKA;;GAEG;AACH;IACE;;OAEG;IACH,uBAFW,uBAAuB,EAKjC;IADC,wCAA6D;CAahE;AAED;IAOE,4BAA0B;IAe1B;;OAEG;IACH,2BAFW,OAAO,EAKjB;IAVD,yBAKW,OAAO,CAHjB;IAUD;;OAEG;IACH
|
|
1
|
+
{"version":3,"file":"uk-address.d.ts","sourceRoot":"","sources":["../../../../../src/form/form-editor/preview/uk-address.js"],"names":[],"mappings":"AAKA;;GAEG;AACH;IACE;;OAEG;IACH,uBAFW,uBAAuB,EAKjC;IADC,wCAA6D;CAahE;AAED;IAOE,4BAA0B;IAe1B;;OAEG;IACH,2BAFW,OAAO,EAKjB;IAVD,yBAKW,OAAO,CAHjB;IAUD;;OAEG;IACH;;;;;;;;;;;;;;;;;;;;;MAKC;CACF;sCAGoE,yCAAyC;0CApEpE,4CAA4C;6CAqE1C,2BAA2B;iCAvEtC,qDAAqD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/form/form-manager/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,KAAK,CAAA;AAE1C,OAAO,EACL,mBAAmB,EAGnB,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,YAAY,mBAAmB,GAAG,mBAAmB,EAAE,MAItC,QAAQ,GAAG,CAAC,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/form/form-manager/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,KAAK,CAAA;AAE1C,OAAO,EACL,mBAAmB,EAGnB,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,YAAY,mBAAmB,GAAG,mBAAmB,EAAE,MAItC,QAAQ,GAAG,CAAC,WAAW,EAAE,sBAiD3C,CAAA;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,eAAe,EAAE,eAAe,GAAG,SAAS,GAC3C,wBAAwB,EAAE,CA8D5B"}
|
|
@@ -14,7 +14,8 @@ export interface AddComponentQueryOptions {
|
|
|
14
14
|
export declare enum FormDefinitionErrorType {
|
|
15
15
|
Unique = "unique",// Unique constraint
|
|
16
16
|
Ref = "ref",// Referential integrity
|
|
17
|
-
Type = "type"
|
|
17
|
+
Type = "type",// General schema type error
|
|
18
|
+
Incompatible = "incompatible"
|
|
18
19
|
}
|
|
19
20
|
export declare enum FormDefinitionError {
|
|
20
21
|
UniquePageId = "unique_page_id",
|
|
@@ -37,6 +38,7 @@ export declare enum FormDefinitionError {
|
|
|
37
38
|
RefConditionItemId = "ref_condition_item_id",
|
|
38
39
|
RefConditionConditionId = "ref_condition_condition_id",
|
|
39
40
|
RefPageComponentList = "ref_page_component_list",
|
|
41
|
+
IncompatibleConditionComponentType = "incompatible_condition_component_type",
|
|
40
42
|
Other = "other"
|
|
41
43
|
}
|
|
42
44
|
export interface ErrorMatchValue {
|
|
@@ -54,6 +56,15 @@ export interface FormDefinitionErrorCauseDetailUnique {
|
|
|
54
56
|
export interface FormDefinitionErrorCauseDetailRef {
|
|
55
57
|
path: FormDefinitionErrorCauseDetailPath;
|
|
56
58
|
}
|
|
59
|
+
export interface FormDefinitionErrorCauseDetailIncompatible {
|
|
60
|
+
path: FormDefinitionErrorCauseDetailPath;
|
|
61
|
+
valueKey?: string;
|
|
62
|
+
incompatibleObject: {
|
|
63
|
+
key?: string;
|
|
64
|
+
value?: unknown;
|
|
65
|
+
};
|
|
66
|
+
reason: string;
|
|
67
|
+
}
|
|
57
68
|
export type FormDefinitionErrorCause = {
|
|
58
69
|
id: FormDefinitionError;
|
|
59
70
|
type: FormDefinitionErrorType.Unique;
|
|
@@ -69,5 +80,10 @@ export type FormDefinitionErrorCause = {
|
|
|
69
80
|
type: FormDefinitionErrorType.Type;
|
|
70
81
|
message: string;
|
|
71
82
|
detail: Context | undefined;
|
|
83
|
+
} | {
|
|
84
|
+
id: FormDefinitionError;
|
|
85
|
+
type: FormDefinitionErrorType.Incompatible;
|
|
86
|
+
message: string;
|
|
87
|
+
detail: FormDefinitionErrorCauseDetailIncompatible;
|
|
72
88
|
};
|
|
73
89
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/form/form-manager/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAA;AAElC,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,qCAAqC,CAAA;AACjE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;IAClC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAGD,oBAAY,uBAAuB;IACjC,MAAM,WAAW,CAAE,oBAAoB;IACvC,GAAG,QAAQ,CAAE,wBAAwB;IACrC,IAAI,SAAS;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/form/form-manager/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './components/index.js';
|
|
|
8
8
|
export * from './conditions/index.js';
|
|
9
9
|
export * from './form/form-definition/index.js';
|
|
10
10
|
export * from './form/form-definition/types.js';
|
|
11
|
+
export * from './form/form-definition/helpers.js';
|
|
11
12
|
export * from './form/form-metadata/index.js';
|
|
12
13
|
export * from './form/form-submission/index.js';
|
|
13
14
|
export * from './form/form-submission/enums.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qCAAqC,CAAA;AACnD,cAAc,qCAAqC,CAAA;AACnD,cAAc,mCAAmC,CAAA;AACjD,cAAc,qCAAqC,CAAA;AACnD,cAAc,qCAAqC,CAAA;AACnD,cAAc,2BAA2B,CAAA;AACzC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,yCAAyC,CAAA;AACvD,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA;AAE9C,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,kCAAkC,CAAA;AACrD,mBAAmB,8BAA8B,CAAA;AACjD,mBAAmB,+BAA+B,CAAA;AAClD,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,qCAAqC,CAAA;AACxD,mBAAmB,mCAAmC,CAAA;AACtD,mBAAmB,qCAAqC,CAAA;AACxD,mBAAmB,yCAAyC,CAAA;AAC5D,mBAAmB,iCAAiC,CAAA;AACpD,mBAAmB,wCAAwC,CAAA;AAC3D,mBAAmB,gCAAgC,CAAA;AACnD,mBAAmB,uBAAuB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kCAAkC,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qCAAqC,CAAA;AACnD,cAAc,qCAAqC,CAAA;AACnD,cAAc,uCAAuC,CAAA;AACrD,cAAc,mCAAmC,CAAA;AACjD,cAAc,qCAAqC,CAAA;AACnD,cAAc,qCAAqC,CAAA;AACnD,cAAc,2BAA2B,CAAA;AACzC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,yCAAyC,CAAA;AACvD,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA;AAE9C,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,kCAAkC,CAAA;AACrD,mBAAmB,8BAA8B,CAAA;AACjD,mBAAmB,+BAA+B,CAAA;AAClD,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,2BAA2B,CAAA;AAC9C,mBAAmB,qCAAqC,CAAA;AACxD,mBAAmB,mCAAmC,CAAA;AACtD,mBAAmB,qCAAqC,CAAA;AACxD,mBAAmB,yCAAyC,CAAA;AAC5D,mBAAmB,iCAAiC,CAAA;AACpD,mBAAmB,wCAAwC,CAAA;AAC3D,mBAAmB,gCAAgC,CAAA;AACnD,mBAAmB,uBAAuB,CAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type FormDefinition } from '~/src/form/form-definition/types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TypeGuard to check if component is a ListComponentsDef
|
|
5
|
+
* @param { FormDefinition | undefined } definition
|
|
6
|
+
* @returns { definition is FormDefinition }
|
|
7
|
+
*/
|
|
8
|
+
export function isFormDefinition(
|
|
9
|
+
definition: FormDefinition | undefined
|
|
10
|
+
): definition is FormDefinition {
|
|
11
|
+
if (!definition) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
return (
|
|
15
|
+
'name' in definition && 'pages' in definition && 'conditions' in definition
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import JoiDate from '@joi/date'
|
|
2
|
-
import JoiBase, { type LanguageMessages } from 'joi'
|
|
2
|
+
import JoiBase, { type CustomHelpers, type LanguageMessages } from 'joi'
|
|
3
3
|
import { v4 as uuidV4 } from 'uuid'
|
|
4
4
|
|
|
5
5
|
import { ComponentType } from '~/src/components/enums.js'
|
|
6
|
+
import { isConditionalType } from '~/src/components/helpers.js'
|
|
6
7
|
import {
|
|
7
8
|
type ComponentDef,
|
|
8
9
|
type ContentComponentsDef,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
type RelativeDateValueData,
|
|
24
25
|
type RelativeDateValueDataV2
|
|
25
26
|
} from '~/src/conditions/types.js'
|
|
27
|
+
import { isFormDefinition } from '~/src/form/form-definition/helpers.js'
|
|
26
28
|
import {
|
|
27
29
|
SchemaVersion,
|
|
28
30
|
type ConditionWrapper,
|
|
@@ -42,9 +44,15 @@ import {
|
|
|
42
44
|
type Section
|
|
43
45
|
} from '~/src/form/form-definition/types.js'
|
|
44
46
|
import { checkErrors } from '~/src/form/form-manager/errors.js'
|
|
45
|
-
import {
|
|
47
|
+
import {
|
|
48
|
+
FormDefinitionError,
|
|
49
|
+
FormDefinitionErrorType
|
|
50
|
+
} from '~/src/form/form-manager/types.js'
|
|
46
51
|
import { ControllerType } from '~/src/pages/enums.js'
|
|
47
|
-
import {
|
|
52
|
+
import {
|
|
53
|
+
hasComponents,
|
|
54
|
+
hasComponentsEvenIfNoNext
|
|
55
|
+
} from '~/src/pages/helpers.js'
|
|
48
56
|
|
|
49
57
|
const Joi = JoiBase.extend(JoiDate) as JoiBase.Root
|
|
50
58
|
|
|
@@ -316,6 +324,48 @@ export const conditionDataSchemaV2 = Joi.object<ConditionDataV2>()
|
|
|
316
324
|
'Value to compare the field against, either fixed or relative date'
|
|
317
325
|
)
|
|
318
326
|
})
|
|
327
|
+
.custom((value: ConditionDataV2, helpers: CustomHelpers<ConditionDataV2>) => {
|
|
328
|
+
const { componentId } = value
|
|
329
|
+
const definition = helpers.state.ancestors.find(isFormDefinition) as
|
|
330
|
+
| FormDefinition
|
|
331
|
+
| undefined
|
|
332
|
+
|
|
333
|
+
// Validation may not have been fired on the full FormDefinition
|
|
334
|
+
// therefore we are unable to verify at this point, but the 'save'
|
|
335
|
+
// will eventually validate the full FormDefinition
|
|
336
|
+
if (!definition) {
|
|
337
|
+
return value
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const foundComponents = definition.pages
|
|
341
|
+
.map((page) =>
|
|
342
|
+
hasComponentsEvenIfNoNext(page)
|
|
343
|
+
? page.components.find((comp) => comp.id === componentId)
|
|
344
|
+
: undefined
|
|
345
|
+
)
|
|
346
|
+
.filter(Boolean)
|
|
347
|
+
|
|
348
|
+
const foundComponentHandlesConditions = foundComponents.length
|
|
349
|
+
? isConditionalType(foundComponents[0]?.type)
|
|
350
|
+
: false
|
|
351
|
+
|
|
352
|
+
return foundComponentHandlesConditions
|
|
353
|
+
? value
|
|
354
|
+
: helpers.error('custom.incompatible', {
|
|
355
|
+
incompatibleObject: {
|
|
356
|
+
key: 'type',
|
|
357
|
+
value: foundComponents[0]
|
|
358
|
+
},
|
|
359
|
+
valueKey: 'componentId',
|
|
360
|
+
value: componentId,
|
|
361
|
+
errorType: FormDefinitionErrorType.Incompatible,
|
|
362
|
+
errorCode: FormDefinitionError.IncompatibleConditionComponentType,
|
|
363
|
+
reason: 'does not support conditions'
|
|
364
|
+
})
|
|
365
|
+
})
|
|
366
|
+
.messages({
|
|
367
|
+
'custom.incompatible': 'Incompatible data value'
|
|
368
|
+
})
|
|
319
369
|
|
|
320
370
|
const conditionGroupSchema = Joi.object<ConditionGroupData>()
|
|
321
371
|
.description('Group of conditions combined with logical operators')
|
|
@@ -85,6 +85,11 @@ export class QuestionPreviewElements {
|
|
|
85
85
|
* @protected
|
|
86
86
|
*/
|
|
87
87
|
_shortDesc = ''
|
|
88
|
+
/**
|
|
89
|
+
* @type {string}
|
|
90
|
+
* @protected
|
|
91
|
+
*/
|
|
92
|
+
_userClasses = ''
|
|
88
93
|
/**
|
|
89
94
|
* @type {string}
|
|
90
95
|
* @protected
|
|
@@ -111,6 +116,7 @@ export class QuestionPreviewElements {
|
|
|
111
116
|
hintText,
|
|
112
117
|
optional,
|
|
113
118
|
shortDesc,
|
|
119
|
+
userClasses,
|
|
114
120
|
usePostcodeLookup,
|
|
115
121
|
items,
|
|
116
122
|
content
|
|
@@ -119,6 +125,7 @@ export class QuestionPreviewElements {
|
|
|
119
125
|
this._hintText = hintText
|
|
120
126
|
this._optional = optional
|
|
121
127
|
this._shortDesc = shortDesc
|
|
128
|
+
this._userClasses = userClasses
|
|
122
129
|
this._items = items
|
|
123
130
|
this._content = content
|
|
124
131
|
this._usePostcodeLookup = usePostcodeLookup ?? false
|
|
@@ -133,6 +140,7 @@ export class QuestionPreviewElements {
|
|
|
133
140
|
hintText: this._hintText,
|
|
134
141
|
optional: this._optional,
|
|
135
142
|
shortDesc: this._shortDesc,
|
|
143
|
+
userClasses: this._userClasses,
|
|
136
144
|
usePostcodeLookup: this._usePostcodeLookup,
|
|
137
145
|
items: this._items,
|
|
138
146
|
content: this._content
|
|
@@ -204,11 +212,25 @@ export const baseElements = /** @type {BaseSettings} */ ({
|
|
|
204
212
|
optional: false,
|
|
205
213
|
question: 'Which quest would you like to pick?',
|
|
206
214
|
hintText: 'Choose one adventure that best suits you.',
|
|
215
|
+
userClasses: '',
|
|
207
216
|
shortDesc: '',
|
|
208
217
|
content: '',
|
|
209
218
|
largeTitle: true
|
|
210
219
|
})
|
|
211
220
|
|
|
221
|
+
export const numberElements = /** @type {NumberSettings} */ ({
|
|
222
|
+
items: [],
|
|
223
|
+
optional: false,
|
|
224
|
+
question: 'Which quest would you like to pick?',
|
|
225
|
+
hintText: 'Choose one adventure that best suits you.',
|
|
226
|
+
userClasses: '',
|
|
227
|
+
shortDesc: '',
|
|
228
|
+
content: '',
|
|
229
|
+
largeTitle: true,
|
|
230
|
+
prefix: '',
|
|
231
|
+
suffix: ''
|
|
232
|
+
})
|
|
233
|
+
|
|
212
234
|
const list1Id = '414d82a3-4cab-416a-bd54-6b86fbd51120'
|
|
213
235
|
const list2Id = '801385a4-81e6-4171-96c3-6c6727d97f22'
|
|
214
236
|
const list3Id = 'e6e3f621-b875-4ca3-a054-cca9149149dd'
|
|
@@ -267,8 +289,115 @@ export function buildPreviewShortAnswer(partialBaseElements, renderMock) {
|
|
|
267
289
|
)
|
|
268
290
|
}
|
|
269
291
|
|
|
292
|
+
export class NumberPreviewElements {
|
|
293
|
+
/**
|
|
294
|
+
* @protected
|
|
295
|
+
*/
|
|
296
|
+
_question = ''
|
|
297
|
+
/** @protected */
|
|
298
|
+
_hintText = ''
|
|
299
|
+
/** @protected */
|
|
300
|
+
_optional = false
|
|
301
|
+
/**
|
|
302
|
+
* @type {string}
|
|
303
|
+
* @protected
|
|
304
|
+
*/
|
|
305
|
+
_shortDesc = ''
|
|
306
|
+
/**
|
|
307
|
+
* @type {string}
|
|
308
|
+
* @protected
|
|
309
|
+
*/
|
|
310
|
+
_userClasses = ''
|
|
311
|
+
/**
|
|
312
|
+
* @type {string}
|
|
313
|
+
* @protected
|
|
314
|
+
*/
|
|
315
|
+
_prefix = ''
|
|
316
|
+
/**
|
|
317
|
+
* @type {string}
|
|
318
|
+
* @protected
|
|
319
|
+
*/
|
|
320
|
+
_suffix = ''
|
|
321
|
+
/**
|
|
322
|
+
* @type {string}
|
|
323
|
+
* @protected
|
|
324
|
+
*/
|
|
325
|
+
_content = ''
|
|
326
|
+
/**
|
|
327
|
+
*
|
|
328
|
+
* @type {ListElement[]}
|
|
329
|
+
* @private
|
|
330
|
+
*/
|
|
331
|
+
_items = []
|
|
332
|
+
/**
|
|
333
|
+
* @protected
|
|
334
|
+
* @type {boolean}
|
|
335
|
+
*/
|
|
336
|
+
_usePostcodeLookup = false
|
|
337
|
+
afterInputsHTML = '<div class="govuk-inset-text">No items added yet.</div>'
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @param {NumberSettings} baseSettings
|
|
341
|
+
*/
|
|
342
|
+
constructor({
|
|
343
|
+
question,
|
|
344
|
+
hintText,
|
|
345
|
+
optional,
|
|
346
|
+
shortDesc,
|
|
347
|
+
userClasses,
|
|
348
|
+
prefix,
|
|
349
|
+
suffix,
|
|
350
|
+
usePostcodeLookup,
|
|
351
|
+
items,
|
|
352
|
+
content
|
|
353
|
+
}) {
|
|
354
|
+
this._question = question
|
|
355
|
+
this._hintText = hintText
|
|
356
|
+
this._optional = optional
|
|
357
|
+
this._shortDesc = shortDesc
|
|
358
|
+
this._userClasses = userClasses
|
|
359
|
+
this._prefix = prefix
|
|
360
|
+
this._suffix = suffix
|
|
361
|
+
this._items = items
|
|
362
|
+
this._content = content
|
|
363
|
+
this._usePostcodeLookup = usePostcodeLookup ?? false
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @returns {NumberSettings}
|
|
368
|
+
*/
|
|
369
|
+
get values() {
|
|
370
|
+
return {
|
|
371
|
+
question: this._question,
|
|
372
|
+
hintText: this._hintText,
|
|
373
|
+
optional: this._optional,
|
|
374
|
+
shortDesc: this._shortDesc,
|
|
375
|
+
userClasses: this._userClasses,
|
|
376
|
+
prefix: this._prefix,
|
|
377
|
+
suffix: this._suffix,
|
|
378
|
+
usePostcodeLookup: this._usePostcodeLookup,
|
|
379
|
+
items: this._items,
|
|
380
|
+
content: this._content
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @param {string} _value
|
|
386
|
+
*/
|
|
387
|
+
setPreviewHTML(_value) {
|
|
388
|
+
// Not implemented for server side render
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @param {HTMLElement} _value
|
|
393
|
+
*/
|
|
394
|
+
setPreviewDOM(_value) {
|
|
395
|
+
// Not implemented for server side render
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
270
399
|
/**
|
|
271
400
|
* @import { ListElement } from '~/src/form/form-editor/types.js'
|
|
272
401
|
* @import { PagePreviewPanelMacro } from '~/src/form/form-editor/macros/types.js'
|
|
273
|
-
* @import { BaseSettings, ListElements, RenderContext, QuestionBaseModel,
|
|
402
|
+
* @import { BaseSettings, ListElements, NumberSettings, RenderContext, QuestionBaseModel, QuestionRenderer, AutocompleteElements, PageOverviewElements, PageRenderer } from '~/src/form/form-editor/preview/types.js'
|
|
274
403
|
*/
|
|
@@ -55,6 +55,9 @@ export interface QuestionBaseModel {
|
|
|
55
55
|
formGroup?: FormGroupAfterInput
|
|
56
56
|
type?: 'text' | 'number' | 'boolean'
|
|
57
57
|
classes?: string
|
|
58
|
+
previewClasses?: string
|
|
59
|
+
prefix?: { text: string }
|
|
60
|
+
suffix?: { text: string }
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
export interface AppPreviewPanelMacro extends AppPreviewPanelTabsMacro {
|
|
@@ -26,6 +26,10 @@ export class ComponentElements {
|
|
|
26
26
|
hintText: '',
|
|
27
27
|
optional: !required,
|
|
28
28
|
shortDesc: '',
|
|
29
|
+
userClasses:
|
|
30
|
+
this._component.options && 'classes' in this._component.options
|
|
31
|
+
? (this._component.options.classes ?? '')
|
|
32
|
+
: '',
|
|
29
33
|
items: [],
|
|
30
34
|
content: ''
|
|
31
35
|
}
|
|
@@ -19,7 +19,10 @@ import {
|
|
|
19
19
|
import { LongAnswerQuestion } from '~/src/form/form-editor/preview/long-answer.js'
|
|
20
20
|
import { Markdown } from '~/src/form/form-editor/preview/markdown.js'
|
|
21
21
|
import { MonthYearQuestion } from '~/src/form/form-editor/preview/month-year.js'
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
NumberComponentPreviewElements,
|
|
24
|
+
NumberOnlyQuestion
|
|
25
|
+
} from '~/src/form/form-editor/preview/number-only.js'
|
|
23
26
|
import { PhoneNumberQuestion } from '~/src/form/form-editor/preview/phone-number.js'
|
|
24
27
|
import { QuestionComponentElements } from '~/src/form/form-editor/preview/question.js'
|
|
25
28
|
import { RadioQuestion } from '~/src/form/form-editor/preview/radio.js'
|
|
@@ -78,6 +81,8 @@ export function mapComponentToPreviewQuestion(questionRenderer, definition) {
|
|
|
78
81
|
questionElements = new SelectComponentElements(component, list)
|
|
79
82
|
} else if (component.type === ComponentType.UkAddressField) {
|
|
80
83
|
questionElements = new UkAddressComponentPreviewElements(component)
|
|
84
|
+
} else if (component.type === ComponentType.NumberField) {
|
|
85
|
+
questionElements = new NumberComponentPreviewElements(component)
|
|
81
86
|
} else if (hasSelectionFields(component) && hasListField(component)) {
|
|
82
87
|
const list = findDefinitionListFromComponent(component, definition)
|
|
83
88
|
questionElements = new ListComponentElements(component, list)
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import { ComponentType } from '~/src/components/enums.js'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Question,
|
|
4
|
+
QuestionComponentElements
|
|
5
|
+
} from '~/src/form/form-editor/preview/question.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @implements {QuestionElements}
|
|
9
|
+
*/
|
|
10
|
+
export class NumberComponentPreviewElements extends QuestionComponentElements {
|
|
11
|
+
/**
|
|
12
|
+
* @param {NumberFieldComponent} component
|
|
13
|
+
*/
|
|
14
|
+
constructor(component) {
|
|
15
|
+
super(component)
|
|
16
|
+
this._prefix = component.options.prefix
|
|
17
|
+
this._suffix = component.options.suffix
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @protected
|
|
22
|
+
* @returns {NumberSettings}
|
|
23
|
+
*/
|
|
24
|
+
_getValues() {
|
|
25
|
+
return {
|
|
26
|
+
...super._getValues(),
|
|
27
|
+
prefix: this._prefix ?? '',
|
|
28
|
+
suffix: this._suffix ?? ''
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
3
32
|
|
|
4
33
|
export class NumberOnlyQuestion extends Question {
|
|
5
34
|
/**
|
|
@@ -8,12 +37,14 @@ export class NumberOnlyQuestion extends Question {
|
|
|
8
37
|
componentType = ComponentType.NumberField
|
|
9
38
|
|
|
10
39
|
/**
|
|
11
|
-
* @param {
|
|
40
|
+
* @param {NumberElements} htmlElements
|
|
12
41
|
* @param {QuestionRenderer} questionRenderer
|
|
13
42
|
*/
|
|
14
43
|
constructor(htmlElements, questionRenderer) {
|
|
15
44
|
super(htmlElements, questionRenderer)
|
|
16
45
|
this._fieldName = 'numberField'
|
|
46
|
+
this._prefix = htmlElements.values.prefix
|
|
47
|
+
this._suffix = htmlElements.values.suffix
|
|
17
48
|
}
|
|
18
49
|
|
|
19
50
|
/**
|
|
@@ -24,8 +55,46 @@ export class NumberOnlyQuestion extends Question {
|
|
|
24
55
|
type: 'number'
|
|
25
56
|
}
|
|
26
57
|
}
|
|
58
|
+
|
|
59
|
+
get prefix() {
|
|
60
|
+
return this._prefix
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} val
|
|
65
|
+
*/
|
|
66
|
+
set prefix(val) {
|
|
67
|
+
this._prefix = val
|
|
68
|
+
this.render()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get suffix() {
|
|
72
|
+
return this._suffix
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {string} val
|
|
77
|
+
*/
|
|
78
|
+
set suffix(val) {
|
|
79
|
+
this._suffix = val
|
|
80
|
+
this.render()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @protected
|
|
85
|
+
*/
|
|
86
|
+
_renderInput() {
|
|
87
|
+
const prefixObj = this.prefix ? { prefix: { text: this.prefix } } : {}
|
|
88
|
+
const suffixObj = this.suffix ? { suffix: { text: this.suffix } } : {}
|
|
89
|
+
return {
|
|
90
|
+
...super._renderInput(),
|
|
91
|
+
...prefixObj,
|
|
92
|
+
...suffixObj
|
|
93
|
+
}
|
|
94
|
+
}
|
|
27
95
|
}
|
|
28
96
|
|
|
29
97
|
/**
|
|
30
|
-
* @import {
|
|
98
|
+
* @import { NumberSettings, NumberElements, QuestionBaseModel, QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
|
|
99
|
+
* @import { NumberFieldComponent } from '~/src/components/types.js'
|
|
31
100
|
*/
|
|
@@ -27,7 +27,8 @@ export class QuestionComponentElements extends ComponentElements {
|
|
|
27
27
|
return {
|
|
28
28
|
...super._getValues(),
|
|
29
29
|
hintText: this._component.hint ?? '',
|
|
30
|
-
shortDesc: this._component.shortDescription ?? ''
|
|
30
|
+
shortDesc: this._component.shortDescription ?? '',
|
|
31
|
+
userClasses: this._component.options.classes ?? ''
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -65,12 +66,17 @@ export class Question extends PreviewComponent {
|
|
|
65
66
|
*/
|
|
66
67
|
constructor(htmlElements, questionRenderer) {
|
|
67
68
|
super(htmlElements, questionRenderer)
|
|
68
|
-
const { hintText } = htmlElements.values
|
|
69
|
+
const { hintText, userClasses } = htmlElements.values
|
|
69
70
|
/**
|
|
70
71
|
* @type {string}
|
|
71
72
|
* @private
|
|
72
73
|
*/
|
|
73
74
|
this._hintText = hintText
|
|
75
|
+
/**
|
|
76
|
+
* @type {string}
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
this._userClasses = userClasses
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
/**
|
|
@@ -94,7 +100,16 @@ export class Question extends PreviewComponent {
|
|
|
94
100
|
* @protected
|
|
95
101
|
*/
|
|
96
102
|
_renderInput() {
|
|
97
|
-
|
|
103
|
+
const renderValues = {
|
|
104
|
+
...super._renderInput(),
|
|
105
|
+
label: this.label,
|
|
106
|
+
hint: this.hint
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...renderValues,
|
|
110
|
+
classes: this._userClasses,
|
|
111
|
+
previewClasses: renderValues.classes ?? ''
|
|
112
|
+
}
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
/**
|
|
@@ -111,6 +126,21 @@ export class Question extends PreviewComponent {
|
|
|
111
126
|
this._hintText = value
|
|
112
127
|
this.render()
|
|
113
128
|
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @type {string}
|
|
132
|
+
*/
|
|
133
|
+
get userClasses() {
|
|
134
|
+
return this._userClasses
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {string} value
|
|
139
|
+
*/
|
|
140
|
+
set userClasses(value) {
|
|
141
|
+
this._userClasses = value
|
|
142
|
+
this.render()
|
|
143
|
+
}
|
|
114
144
|
}
|
|
115
145
|
|
|
116
146
|
/**
|
|
@@ -20,6 +20,7 @@ export interface BaseSettings {
|
|
|
20
20
|
hintText: string
|
|
21
21
|
optional: boolean
|
|
22
22
|
shortDesc: string
|
|
23
|
+
userClasses: string
|
|
23
24
|
items: ListElement[]
|
|
24
25
|
content: string
|
|
25
26
|
attributes?: Record<string, string>
|
|
@@ -58,6 +59,15 @@ export interface AutocompleteElements extends QuestionElements {
|
|
|
58
59
|
autocompleteOptions: string
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
export interface NumberSettings extends BaseSettings {
|
|
63
|
+
prefix: string
|
|
64
|
+
suffix: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface NumberElements extends DomElementsBase {
|
|
68
|
+
readonly values: NumberSettings
|
|
69
|
+
}
|
|
70
|
+
|
|
61
71
|
export interface RenderBase {
|
|
62
72
|
render(questionTemplate: string, renderContext: RenderContext): void
|
|
63
73
|
}
|
|
@@ -50,6 +50,16 @@ export const checkErrors = (
|
|
|
50
50
|
return
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
if (
|
|
54
|
+
errorDetails.type === FormDefinitionErrorType.Incompatible &&
|
|
55
|
+
err.code === 'custom.incompatible'
|
|
56
|
+
// Match any key
|
|
57
|
+
) {
|
|
58
|
+
err.local.errorCode = formError
|
|
59
|
+
err.local.errorType = FormDefinitionErrorType.Incompatible
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
53
63
|
err.local.errorType = FormDefinitionErrorType.Type
|
|
54
64
|
}
|
|
55
65
|
})
|
|
@@ -95,6 +105,26 @@ export function getErrors(
|
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
|
|
108
|
+
if (
|
|
109
|
+
detail.context?.errorType === FormDefinitionErrorType.Incompatible &&
|
|
110
|
+
detail.context.errorCode
|
|
111
|
+
) {
|
|
112
|
+
return {
|
|
113
|
+
id: /** @type {FormDefinitionError} */ detail.context.errorCode,
|
|
114
|
+
type: FormDefinitionErrorType.Incompatible,
|
|
115
|
+
message: detail.message,
|
|
116
|
+
detail: {
|
|
117
|
+
path: detail.path,
|
|
118
|
+
key: detail.context.key,
|
|
119
|
+
valueKey: detail.context.valueKey,
|
|
120
|
+
value: detail.context.value,
|
|
121
|
+
label: detail.context.label,
|
|
122
|
+
incompatibleObject: detail.context.incompatibleObject,
|
|
123
|
+
reason: detail.context.reason
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
98
128
|
// Catch all others
|
|
99
129
|
return {
|
|
100
130
|
id: FormDefinitionError.Other,
|