@defra/forms-model 3.0.568 → 3.0.570
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/components/component-types.js +24 -0
- package/dist/module/components/component-types.js.map +1 -1
- package/dist/module/components/enums.js +4 -0
- package/dist/module/components/enums.js.map +1 -1
- package/dist/module/components/types.js.map +1 -1
- package/dist/module/conditions/condition-operators.js +5 -1
- package/dist/module/conditions/condition-operators.js.map +1 -1
- package/dist/module/form/form-editor/index.js +8 -4
- package/dist/module/form/form-editor/index.js.map +1 -1
- package/dist/module/form/form-editor/preview/helpers.js +5 -1
- package/dist/module/form/form-editor/preview/helpers.js.map +1 -1
- package/dist/module/form/form-editor/types.js.map +1 -1
- package/dist/module/pages/helpers.js +0 -21
- package/dist/module/pages/helpers.js.map +1 -1
- package/dist/module/pages/index.js +1 -1
- package/dist/module/pages/index.js.map +1 -1
- package/dist/types/components/component-types.d.ts.map +1 -1
- package/dist/types/components/enums.d.ts +5 -1
- package/dist/types/components/enums.d.ts.map +1 -1
- package/dist/types/components/types.d.ts +50 -1
- package/dist/types/components/types.d.ts.map +1 -1
- package/dist/types/conditions/condition-operators.d.ts +16 -0
- package/dist/types/conditions/condition-operators.d.ts.map +1 -1
- package/dist/types/form/form-editor/index.d.ts +5 -1
- package/dist/types/form/form-editor/index.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/helpers.d.ts.map +1 -1
- package/dist/types/form/form-editor/types.d.ts +15 -2
- package/dist/types/form/form-editor/types.d.ts.map +1 -1
- package/dist/types/pages/helpers.d.ts +0 -6
- package/dist/types/pages/helpers.d.ts.map +1 -1
- package/dist/types/pages/index.d.ts +1 -1
- package/dist/types/pages/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/schemas/date-sub-schema.json +1 -1
- package/schemas/form-editor-input-page-schema.json +1 -0
- package/schemas/question-type-full-schema.json +5 -1
- package/schemas/question-type-schema.json +1 -0
- package/src/components/component-types.ts +28 -0
- package/src/components/enums.ts +5 -1
- package/src/components/types.ts +58 -0
- package/src/conditions/condition-operators.ts +5 -1
- package/src/form/form-editor/index.ts +30 -3
- package/src/form/form-editor/preview/helpers.js +5 -1
- package/src/form/form-editor/types.ts +24 -1
- package/src/pages/helpers.ts +0 -21
- package/src/pages/index.ts +0 -1
package/src/components/types.ts
CHANGED
|
@@ -27,6 +27,7 @@ interface FormFieldBase {
|
|
|
27
27
|
optionalText?: boolean
|
|
28
28
|
classes?: string
|
|
29
29
|
customValidationMessages?: LanguageMessages
|
|
30
|
+
instructionText?: string
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -164,6 +165,59 @@ export interface UkAddressFieldComponent extends FormFieldBase {
|
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
|
|
168
|
+
// Precise Location Fields
|
|
169
|
+
export interface EastingNorthingFieldComponent extends FormFieldBase {
|
|
170
|
+
type: ComponentType.EastingNorthingField
|
|
171
|
+
options: FormFieldBase['options'] & {
|
|
172
|
+
condition?: string
|
|
173
|
+
customValidationMessage?: string
|
|
174
|
+
}
|
|
175
|
+
schema?: {
|
|
176
|
+
easting?: {
|
|
177
|
+
min?: number
|
|
178
|
+
max?: number
|
|
179
|
+
}
|
|
180
|
+
northing?: {
|
|
181
|
+
min?: number
|
|
182
|
+
max?: number
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface OsGridRefFieldComponent extends FormFieldBase {
|
|
188
|
+
type: ComponentType.OsGridRefField
|
|
189
|
+
options: FormFieldBase['options'] & {
|
|
190
|
+
condition?: string
|
|
191
|
+
customValidationMessage?: string
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface NationalGridFieldNumberFieldComponent extends FormFieldBase {
|
|
196
|
+
type: ComponentType.NationalGridFieldNumberField
|
|
197
|
+
options: FormFieldBase['options'] & {
|
|
198
|
+
condition?: string
|
|
199
|
+
customValidationMessage?: string
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface LatLongFieldComponent extends FormFieldBase {
|
|
204
|
+
type: ComponentType.LatLongField
|
|
205
|
+
options: FormFieldBase['options'] & {
|
|
206
|
+
condition?: string
|
|
207
|
+
customValidationMessage?: string
|
|
208
|
+
}
|
|
209
|
+
schema?: {
|
|
210
|
+
latitude?: {
|
|
211
|
+
min?: number
|
|
212
|
+
max?: number
|
|
213
|
+
}
|
|
214
|
+
longitude?: {
|
|
215
|
+
min?: number
|
|
216
|
+
max?: number
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
167
221
|
// Date Fields
|
|
168
222
|
export interface DatePartsFieldComponent extends DateFieldBase {
|
|
169
223
|
type: ComponentType.DatePartsField
|
|
@@ -270,6 +324,10 @@ export type InputFieldsComponentsDef =
|
|
|
270
324
|
| DatePartsFieldComponent
|
|
271
325
|
| UkAddressFieldComponent
|
|
272
326
|
| FileUploadFieldComponent
|
|
327
|
+
| EastingNorthingFieldComponent
|
|
328
|
+
| OsGridRefFieldComponent
|
|
329
|
+
| NationalGridFieldNumberFieldComponent
|
|
330
|
+
| LatLongFieldComponent
|
|
273
331
|
|
|
274
332
|
// Components that render content
|
|
275
333
|
export type ContentComponentsDef =
|
|
@@ -80,7 +80,11 @@ export const customOperators = {
|
|
|
80
80
|
[ComponentType.EmailAddressField]: withDefaults(textFieldOperators),
|
|
81
81
|
[ComponentType.TelephoneNumberField]: defaultOperators,
|
|
82
82
|
[ComponentType.SelectField]: defaultOperators,
|
|
83
|
-
[ComponentType.YesNoField]: defaultOperators
|
|
83
|
+
[ComponentType.YesNoField]: defaultOperators,
|
|
84
|
+
[ComponentType.EastingNorthingField]: defaultOperators,
|
|
85
|
+
[ComponentType.OsGridRefField]: defaultOperators,
|
|
86
|
+
[ComponentType.NationalGridFieldNumberField]: defaultOperators,
|
|
87
|
+
[ComponentType.LatLongField]: defaultOperators
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
export function getOperatorNames(fieldType?: ConditionalComponentType) {
|
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
export enum QuestionTypeSubGroup {
|
|
20
20
|
WrittenAnswerSubGroup = 'writtenAnswerSub',
|
|
21
21
|
DateSubGroup = 'dateSub',
|
|
22
|
-
ListSubGroup = 'listSub'
|
|
22
|
+
ListSubGroup = 'listSub',
|
|
23
|
+
LocationSubGroup = 'locationSub'
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export const pageTypeSchema = Joi.string()
|
|
@@ -32,6 +33,7 @@ export const questionTypeSchema = Joi.string()
|
|
|
32
33
|
.valid(
|
|
33
34
|
QuestionTypeSubGroup.WrittenAnswerSubGroup,
|
|
34
35
|
QuestionTypeSubGroup.DateSubGroup,
|
|
36
|
+
QuestionTypeSubGroup.LocationSubGroup,
|
|
35
37
|
ComponentType.UkAddressField,
|
|
36
38
|
ComponentType.TelephoneNumberField,
|
|
37
39
|
ComponentType.FileUploadField,
|
|
@@ -60,7 +62,11 @@ export const questionTypeFullSchema = Joi.string()
|
|
|
60
62
|
ComponentType.CheckboxesField,
|
|
61
63
|
ComponentType.RadiosField,
|
|
62
64
|
ComponentType.AutocompleteField,
|
|
63
|
-
ComponentType.SelectField
|
|
65
|
+
ComponentType.SelectField,
|
|
66
|
+
ComponentType.EastingNorthingField,
|
|
67
|
+
ComponentType.OsGridRefField,
|
|
68
|
+
ComponentType.NationalGridFieldNumberField,
|
|
69
|
+
ComponentType.LatLongField
|
|
64
70
|
)
|
|
65
71
|
.description('The specific component type to use for this question')
|
|
66
72
|
|
|
@@ -76,6 +82,8 @@ export const writtenAnswerSubSchema = Joi.string()
|
|
|
76
82
|
export const dateSubSchema = Joi.string()
|
|
77
83
|
.required()
|
|
78
84
|
.valid(ComponentType.DatePartsField, ComponentType.MonthYearField)
|
|
85
|
+
.description('Subtype for date-related questions')
|
|
86
|
+
|
|
79
87
|
export const listSubSchema = Joi.string()
|
|
80
88
|
.required()
|
|
81
89
|
.valid(
|
|
@@ -85,7 +93,17 @@ export const listSubSchema = Joi.string()
|
|
|
85
93
|
ComponentType.AutocompleteField,
|
|
86
94
|
ComponentType.SelectField
|
|
87
95
|
)
|
|
88
|
-
.description('Subtype for
|
|
96
|
+
.description('Subtype for list-related questions')
|
|
97
|
+
|
|
98
|
+
export const locationSubSchema = Joi.string()
|
|
99
|
+
.required()
|
|
100
|
+
.valid(
|
|
101
|
+
ComponentType.EastingNorthingField,
|
|
102
|
+
ComponentType.OsGridRefField,
|
|
103
|
+
ComponentType.NationalGridFieldNumberField,
|
|
104
|
+
ComponentType.LatLongField
|
|
105
|
+
)
|
|
106
|
+
.description('Subtype for location-related questions')
|
|
89
107
|
|
|
90
108
|
export const nameSchema = Joi.string()
|
|
91
109
|
.trim()
|
|
@@ -103,6 +121,14 @@ export const hintTextSchema = Joi.string()
|
|
|
103
121
|
.allow('')
|
|
104
122
|
.description('Optional guidance text displayed below the question')
|
|
105
123
|
|
|
124
|
+
export const instructionTextSchema = Joi.string()
|
|
125
|
+
.trim()
|
|
126
|
+
.optional()
|
|
127
|
+
.allow('')
|
|
128
|
+
.description(
|
|
129
|
+
'Optional instruction text with markdown support to help users answer the question'
|
|
130
|
+
)
|
|
131
|
+
|
|
106
132
|
export const questionOptionalSchema = Joi.string()
|
|
107
133
|
.trim()
|
|
108
134
|
.optional()
|
|
@@ -512,6 +538,7 @@ export const questionDetailsFullSchema = {
|
|
|
512
538
|
fileTypesSchema,
|
|
513
539
|
hintTextSchema,
|
|
514
540
|
imageTypesSchema,
|
|
541
|
+
instructionTextSchema,
|
|
515
542
|
jsEnabledSchema,
|
|
516
543
|
listForQuestionSchema,
|
|
517
544
|
listItemCountSchema,
|
|
@@ -57,7 +57,11 @@ const InputFieldComponentDictionary = {
|
|
|
57
57
|
[ComponentType.CheckboxesField]: CheckboxQuestion,
|
|
58
58
|
[ComponentType.SelectField]: SelectQuestion,
|
|
59
59
|
[ComponentType.YesNoField]: YesNoQuestion,
|
|
60
|
-
[ComponentType.FileUploadField]: SupportingEvidenceQuestion
|
|
60
|
+
[ComponentType.FileUploadField]: SupportingEvidenceQuestion,
|
|
61
|
+
[ComponentType.EastingNorthingField]: ShortAnswerQuestion,
|
|
62
|
+
[ComponentType.OsGridRefField]: ShortAnswerQuestion,
|
|
63
|
+
[ComponentType.NationalGridFieldNumberField]: ShortAnswerQuestion,
|
|
64
|
+
[ComponentType.LatLongField]: ShortAnswerQuestion
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
/**
|
|
@@ -30,6 +30,11 @@ export interface FormEditor {
|
|
|
30
30
|
*/
|
|
31
31
|
dateSub: string
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* The sub-type of location
|
|
35
|
+
*/
|
|
36
|
+
locationSub: string
|
|
37
|
+
|
|
33
38
|
/**
|
|
34
39
|
* The sub-type of lists
|
|
35
40
|
*/
|
|
@@ -60,6 +65,16 @@ export interface FormEditor {
|
|
|
60
65
|
*/
|
|
61
66
|
shortDescription: string
|
|
62
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The value of checkbox to reveal instruction text field
|
|
70
|
+
*/
|
|
71
|
+
giveInstructions: string
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The instruction text for location components (optional)
|
|
75
|
+
*/
|
|
76
|
+
instructionText: string
|
|
77
|
+
|
|
63
78
|
/**
|
|
64
79
|
* The value of checkbox to reveal heading and guidance section
|
|
65
80
|
*/
|
|
@@ -283,7 +298,12 @@ export interface FormEditor {
|
|
|
283
298
|
|
|
284
299
|
export type FormEditorInputPage = Pick<
|
|
285
300
|
FormEditor,
|
|
286
|
-
|
|
301
|
+
| 'pageType'
|
|
302
|
+
| 'questionType'
|
|
303
|
+
| 'writtenAnswerSub'
|
|
304
|
+
| 'dateSub'
|
|
305
|
+
| 'locationSub'
|
|
306
|
+
| 'listSub'
|
|
287
307
|
>
|
|
288
308
|
|
|
289
309
|
export type FormEditorInputCheckAnswersSettings = Pick<
|
|
@@ -328,6 +348,8 @@ export type FormEditorInputQuestion = Pick<
|
|
|
328
348
|
| 'listItemsData'
|
|
329
349
|
| 'jsEnabled'
|
|
330
350
|
| 'usePostcodeLookup'
|
|
351
|
+
| 'giveInstructions'
|
|
352
|
+
| 'instructionText'
|
|
331
353
|
>
|
|
332
354
|
|
|
333
355
|
export type FormEditorInputPageSettings = Pick<
|
|
@@ -522,6 +544,7 @@ export type GovukStringField = Omit<GovukField, 'value'> & { value: string }
|
|
|
522
544
|
export interface FormEditorGovukField {
|
|
523
545
|
question?: GovukField
|
|
524
546
|
hintText?: GovukField
|
|
547
|
+
instructionText?: GovukField
|
|
525
548
|
questionOptional?: GovukField
|
|
526
549
|
shortDescription?: GovukField
|
|
527
550
|
fileTypes?: GovukField
|
package/src/pages/helpers.ts
CHANGED
|
@@ -135,27 +135,6 @@ export function showRepeaterSettings(page: Page): boolean {
|
|
|
135
135
|
return true
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
/**
|
|
139
|
-
* High level check for whether file upload component should be omitted
|
|
140
|
-
* @param { Page | undefined } page
|
|
141
|
-
* @returns {boolean}
|
|
142
|
-
*/
|
|
143
|
-
export function omitFileUploadComponent(page: Page | undefined): boolean {
|
|
144
|
-
if (page?.controller === ControllerType.Repeat) {
|
|
145
|
-
return true
|
|
146
|
-
}
|
|
147
|
-
if (!hasComponents(page)) {
|
|
148
|
-
return false
|
|
149
|
-
}
|
|
150
|
-
if (page.components.length > 1) {
|
|
151
|
-
return true
|
|
152
|
-
}
|
|
153
|
-
if (includesFileUploadField(page.components)) {
|
|
154
|
-
return true
|
|
155
|
-
}
|
|
156
|
-
return false
|
|
157
|
-
}
|
|
158
|
-
|
|
159
138
|
/**
|
|
160
139
|
* Gets page title, or title of first question (if no page title set)
|
|
161
140
|
* @param {Page} page
|