@defra/forms-model 3.0.563 → 3.0.565
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-editor/__stubs__/preview.js +8 -0
- package/dist/module/form/form-editor/__stubs__/preview.js.map +1 -1
- package/dist/module/form/form-editor/index.js +2 -2
- package/dist/module/form/form-editor/index.js.map +1 -1
- package/dist/module/form/form-editor/preview/autocomplete.js +2 -1
- package/dist/module/form/form-editor/preview/autocomplete.js.map +1 -1
- package/dist/module/form/form-editor/preview/controller/page-controller.js.map +1 -1
- package/dist/module/form/form-editor/preview/fieldset-question.js +12 -2
- package/dist/module/form/form-editor/preview/fieldset-question.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/preview.js +2 -1
- package/dist/module/form/form-editor/preview/preview.js.map +1 -1
- package/dist/module/form/form-editor/preview/select-sortable.js +2 -1
- package/dist/module/form/form-editor/preview/select-sortable.js.map +1 -1
- package/dist/module/form/form-editor/preview/select.js +2 -1
- package/dist/module/form/form-editor/preview/select.js.map +1 -1
- package/dist/module/form/form-editor/preview/types.js.map +1 -1
- package/dist/module/form/form-editor/preview/uk-address.js +58 -1
- package/dist/module/form/form-editor/preview/uk-address.js.map +1 -1
- package/dist/module/form/form-editor/preview/utils.js +9 -0
- package/dist/module/form/form-editor/preview/utils.js.map +1 -0
- package/dist/module/form/form-editor/types.js.map +1 -1
- package/dist/types/form/form-editor/__stubs__/preview.d.ts +6 -1
- package/dist/types/form/form-editor/__stubs__/preview.d.ts.map +1 -1
- package/dist/types/form/form-editor/index.d.ts +2 -2
- package/dist/types/form/form-editor/index.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/autocomplete.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/controller/page-controller.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/fieldset-question.d.ts +0 -14
- package/dist/types/form/form-editor/preview/fieldset-question.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/preview.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/select-sortable.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/select.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/types.d.ts +1 -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 +37 -0
- package/dist/types/form/form-editor/preview/uk-address.d.ts.map +1 -1
- package/dist/types/form/form-editor/preview/utils.d.ts +6 -0
- package/dist/types/form/form-editor/preview/utils.d.ts.map +1 -0
- package/dist/types/form/form-editor/types.d.ts +10 -0
- package/dist/types/form/form-editor/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/form/form-editor/__stubs__/preview.js +16 -1
- package/src/form/form-editor/index.ts +7 -3
- package/src/form/form-editor/preview/autocomplete.js +2 -1
- package/src/form/form-editor/preview/controller/page-controller.js +1 -0
- package/src/form/form-editor/preview/fieldset-question.js +11 -2
- package/src/form/form-editor/preview/helpers.js +6 -1
- package/src/form/form-editor/preview/preview.js +2 -1
- package/src/form/form-editor/preview/select-sortable.js +2 -1
- package/src/form/form-editor/preview/select.js +2 -1
- package/src/form/form-editor/preview/types.ts +1 -0
- package/src/form/form-editor/preview/uk-address.js +59 -1
- package/src/form/form-editor/preview/utils.js +8 -0
- package/src/form/form-editor/types.ts +11 -0
|
@@ -2,6 +2,7 @@ import { ComponentType } from '~/src/components/enums.js'
|
|
|
2
2
|
import { autoCompleteOptionsSchema } from '~/src/form/form-editor/index.js'
|
|
3
3
|
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
|
4
4
|
import { Question } from '~/src/form/form-editor/preview/question.js'
|
|
5
|
+
import { buildCombinedId } from '~/src/form/form-editor/preview/utils.js'
|
|
5
6
|
|
|
6
7
|
export class AutocompleteListQuestion extends Question {
|
|
7
8
|
/**
|
|
@@ -68,7 +69,7 @@ export class AutocompleteQuestion extends AutocompleteListQuestion {
|
|
|
68
69
|
|
|
69
70
|
get renderInput() {
|
|
70
71
|
return {
|
|
71
|
-
id: this._fieldName,
|
|
72
|
+
id: buildCombinedId(this._fieldName, this._id),
|
|
72
73
|
name: this._fieldName,
|
|
73
74
|
attributes: { 'data-module': 'govuk-accessible-autocomplete' },
|
|
74
75
|
hint: this.hint,
|
|
@@ -34,6 +34,7 @@ export class PreviewPageController extends PreviewPageControllerBase {
|
|
|
34
34
|
const questions = components.map(
|
|
35
35
|
mapComponentToPreviewQuestion(questionRenderer, definition)
|
|
36
36
|
)
|
|
37
|
+
|
|
37
38
|
const firstQuestion = /** @type { Markdown | undefined | Question } */ (
|
|
38
39
|
questions.shift()
|
|
39
40
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ComponentType } from '~/src/components/enums.js'
|
|
2
2
|
import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
|
|
3
3
|
import { Question } from '~/src/form/form-editor/preview/question.js'
|
|
4
|
+
import { buildCombinedId } from '~/src/form/form-editor/preview/utils.js'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Simple extension of Question that uses fieldset instead of label - not exported
|
|
@@ -12,9 +13,13 @@ export class FieldsetQuestion extends Question {
|
|
|
12
13
|
*/
|
|
13
14
|
componentType = ComponentType.TextField
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @protected
|
|
18
|
+
* @returns {QuestionBaseModel}
|
|
19
|
+
*/
|
|
20
|
+
_renderInput() {
|
|
16
21
|
return {
|
|
17
|
-
id: this._fieldName,
|
|
22
|
+
id: buildCombinedId(this._fieldName, this._id),
|
|
18
23
|
name: this._fieldName,
|
|
19
24
|
fieldset: this.fieldSet,
|
|
20
25
|
hint: this.hint,
|
|
@@ -23,3 +28,7 @@ export class FieldsetQuestion extends Question {
|
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @import { QuestionBaseModel } from '~/src/form/form-editor/macros/types.js'
|
|
34
|
+
*/
|
|
@@ -26,7 +26,10 @@ import { RadioQuestion } from '~/src/form/form-editor/preview/radio.js'
|
|
|
26
26
|
import { SelectQuestion } from '~/src/form/form-editor/preview/select.js'
|
|
27
27
|
import { ShortAnswerQuestion } from '~/src/form/form-editor/preview/short-answer.js'
|
|
28
28
|
import { SupportingEvidenceQuestion } from '~/src/form/form-editor/preview/supporting-evidence.js'
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
UkAddressComponentPreviewElements,
|
|
31
|
+
UkAddressQuestion
|
|
32
|
+
} from '~/src/form/form-editor/preview/uk-address.js'
|
|
30
33
|
import { YesNoQuestion } from '~/src/form/form-editor/preview/yes-no.js'
|
|
31
34
|
import { findDefinitionListFromComponent } from '~/src/form/utils/list.js'
|
|
32
35
|
/**
|
|
@@ -73,6 +76,8 @@ export function mapComponentToPreviewQuestion(questionRenderer, definition) {
|
|
|
73
76
|
) {
|
|
74
77
|
const list = findDefinitionListFromComponent(component, definition)
|
|
75
78
|
questionElements = new SelectComponentElements(component, list)
|
|
79
|
+
} else if (component.type === ComponentType.UkAddressField) {
|
|
80
|
+
questionElements = new UkAddressComponentPreviewElements(component)
|
|
76
81
|
} else if (hasSelectionFields(component) && hasListField(component)) {
|
|
77
82
|
const list = findDefinitionListFromComponent(component, definition)
|
|
78
83
|
questionElements = new ListComponentElements(component, list)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentType } from '~/src/components/enums.js'
|
|
2
2
|
import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
|
|
3
|
+
import { buildCombinedId } from '~/src/form/form-editor/preview/utils.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @abstract
|
|
@@ -139,7 +140,7 @@ export class PreviewComponent {
|
|
|
139
140
|
*/
|
|
140
141
|
_renderInput() {
|
|
141
142
|
return {
|
|
142
|
-
id: this._fieldName,
|
|
143
|
+
id: buildCombinedId(this._fieldName, this._id),
|
|
143
144
|
name: this._fieldName,
|
|
144
145
|
classes: this._highlighted ? HIGHLIGHT_CLASS : ''
|
|
145
146
|
}
|
|
@@ -2,6 +2,7 @@ import { ComponentType } from '~/src/components/enums.js'
|
|
|
2
2
|
import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
|
|
3
3
|
import { ListSortableQuestion } from '~/src/form/form-editor/preview/list-sortable.js'
|
|
4
4
|
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
|
5
|
+
import { buildCombinedId } from '~/src/form/form-editor/preview/utils.js'
|
|
5
6
|
|
|
6
7
|
export class SelectSortableQuestion extends ListSortableQuestion {
|
|
7
8
|
_questionTemplate = PreviewComponent.PATH + 'selectfield.njk'
|
|
@@ -34,7 +35,7 @@ export class SelectSortableQuestion extends ListSortableQuestion {
|
|
|
34
35
|
const highlightedClass = this._highlighted ? HIGHLIGHT_CLASS : ''
|
|
35
36
|
|
|
36
37
|
return {
|
|
37
|
-
id: this._fieldName,
|
|
38
|
+
id: buildCombinedId(this._fieldName, this._id),
|
|
38
39
|
name: this._fieldName,
|
|
39
40
|
hint: this.hint,
|
|
40
41
|
label: this.label,
|
|
@@ -2,6 +2,7 @@ import { ComponentType } from '~/src/components/enums.js'
|
|
|
2
2
|
import { HIGHLIGHT_CLASS } from '~/src/form/form-editor/preview/constants.js'
|
|
3
3
|
import { ListQuestion } from '~/src/form/form-editor/preview/list.js'
|
|
4
4
|
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
|
5
|
+
import { buildCombinedId } from '~/src/form/form-editor/preview/utils.js'
|
|
5
6
|
|
|
6
7
|
export class SelectQuestion extends ListQuestion {
|
|
7
8
|
_questionTemplate = PreviewComponent.PATH + 'selectfield.njk'
|
|
@@ -35,7 +36,7 @@ export class SelectQuestion extends ListQuestion {
|
|
|
35
36
|
const highlightedClass = this._highlighted ? HIGHLIGHT_CLASS : ''
|
|
36
37
|
|
|
37
38
|
return {
|
|
38
|
-
id: this._fieldName,
|
|
39
|
+
id: buildCombinedId(this._fieldName, this._id),
|
|
39
40
|
name: this._fieldName,
|
|
40
41
|
hint: this.hint,
|
|
41
42
|
label: this.label,
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { ComponentType } from '~/src/components/enums.js'
|
|
2
2
|
import { FieldsetQuestion } from '~/src/form/form-editor/preview/fieldset-question.js'
|
|
3
3
|
import { PreviewComponent } from '~/src/form/form-editor/preview/preview.js'
|
|
4
|
+
import { QuestionComponentElements } from '~/src/form/form-editor/preview/question.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @implements {QuestionElements}
|
|
8
|
+
*/
|
|
9
|
+
export class UkAddressComponentPreviewElements extends QuestionComponentElements {
|
|
10
|
+
/**
|
|
11
|
+
* @param {UkAddressFieldComponent} component
|
|
12
|
+
*/
|
|
13
|
+
constructor(component) {
|
|
14
|
+
super(component)
|
|
15
|
+
this._usePostcodeLookup = component.options.usePostcodeLookup
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @protected
|
|
20
|
+
* @returns {BaseSettings}
|
|
21
|
+
*/
|
|
22
|
+
_getValues() {
|
|
23
|
+
return {
|
|
24
|
+
...super._getValues(),
|
|
25
|
+
usePostcodeLookup: this._usePostcodeLookup
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
4
29
|
|
|
5
30
|
export class UkAddressQuestion extends FieldsetQuestion {
|
|
6
31
|
/**
|
|
@@ -9,8 +34,41 @@ export class UkAddressQuestion extends FieldsetQuestion {
|
|
|
9
34
|
componentType = ComponentType.UkAddressField
|
|
10
35
|
_questionTemplate = PreviewComponent.PATH + 'ukaddressfield.njk'
|
|
11
36
|
_fieldName = 'addressField'
|
|
37
|
+
_usePostcodeLookup = false
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {QuestionElements} htmlElements
|
|
41
|
+
* @param {QuestionRenderer} questionRenderer
|
|
42
|
+
*/
|
|
43
|
+
constructor(htmlElements, questionRenderer) {
|
|
44
|
+
super(htmlElements, questionRenderer)
|
|
45
|
+
this._usePostcodeLookup = htmlElements.values.usePostcodeLookup ?? false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get usePostcodeLookup() {
|
|
49
|
+
return this._usePostcodeLookup
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {boolean} val
|
|
54
|
+
*/
|
|
55
|
+
set usePostcodeLookup(val) {
|
|
56
|
+
this._usePostcodeLookup = val
|
|
57
|
+
this.render()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
_renderInput() {
|
|
64
|
+
return {
|
|
65
|
+
...super._renderInput(),
|
|
66
|
+
usePostcodeLookup: this.usePostcodeLookup
|
|
67
|
+
}
|
|
68
|
+
}
|
|
12
69
|
}
|
|
13
70
|
|
|
14
71
|
/**
|
|
15
|
-
* @import {
|
|
72
|
+
* @import { BaseSettings, QuestionElements, QuestionRenderer } from '~/src/form/form-editor/preview/types.js'
|
|
73
|
+
* @import { UkAddressFieldComponent } from '~/src/components/types.js'
|
|
16
74
|
*/
|
|
@@ -506,6 +506,17 @@ export type GovukFieldQuestionOptional = Omit<GovukField, 'name' | 'items'> & {
|
|
|
506
506
|
]
|
|
507
507
|
}
|
|
508
508
|
|
|
509
|
+
export type GovukFieldUsePostcodeLookup = Omit<GovukField, 'name' | 'items'> & {
|
|
510
|
+
name: 'usePostcodeLookup'
|
|
511
|
+
items: [
|
|
512
|
+
{
|
|
513
|
+
text?: string
|
|
514
|
+
value?: string
|
|
515
|
+
checked: boolean
|
|
516
|
+
}
|
|
517
|
+
]
|
|
518
|
+
}
|
|
519
|
+
|
|
509
520
|
export type GovukStringField = Omit<GovukField, 'value'> & { value: string }
|
|
510
521
|
|
|
511
522
|
export interface FormEditorGovukField {
|