@defra/forms-engine-plugin 5.0.0-alpha.1 → 5.0.0-alpha.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.
Files changed (31) hide show
  1. package/.public/javascripts/application.min.js.map +1 -1
  2. package/.public/javascripts/shared.min.js +1 -1
  3. package/.public/javascripts/shared.min.js.map +1 -1
  4. package/.server/client/javascripts/shared.d.ts +1 -0
  5. package/.server/client/javascripts/shared.js +1 -0
  6. package/.server/client/javascripts/shared.js.map +1 -1
  7. package/.server/server/plugins/engine/components/PaymentField.d.ts +1 -0
  8. package/.server/server/plugins/engine/components/PaymentField.js +8 -1
  9. package/.server/server/plugins/engine/components/PaymentField.js.map +1 -1
  10. package/.server/server/plugins/engine/i18n/createFormTranslator.js +7 -0
  11. package/.server/server/plugins/engine/i18n/createFormTranslator.js.map +1 -1
  12. package/.server/server/plugins/engine/i18n/translations/cy.json +16 -2
  13. package/.server/server/plugins/engine/i18n/translations/en-GB.json +15 -1
  14. package/.server/server/plugins/engine/i18n/types.d.ts +1 -0
  15. package/.server/server/plugins/engine/i18n/types.js.map +1 -1
  16. package/.server/server/plugins/engine/pageControllers/QuestionPageController.js +5 -1
  17. package/.server/server/plugins/engine/pageControllers/QuestionPageController.js.map +1 -1
  18. package/.server/server/plugins/engine/views/components/multilinetextfield.html +12 -1
  19. package/.server/server/plugins/engine/views/components/paymentfield.html +1 -1
  20. package/.server/server/plugins/engine/views/partials/preview-banner.html +3 -1
  21. package/package.json +1 -1
  22. package/src/client/javascripts/shared.js +1 -0
  23. package/src/server/plugins/engine/components/PaymentField.ts +6 -1
  24. package/src/server/plugins/engine/i18n/createFormTranslator.ts +21 -1
  25. package/src/server/plugins/engine/i18n/translations/cy.json +16 -2
  26. package/src/server/plugins/engine/i18n/translations/en-GB.json +15 -1
  27. package/src/server/plugins/engine/i18n/types.ts +1 -0
  28. package/src/server/plugins/engine/pageControllers/QuestionPageController.ts +8 -3
  29. package/src/server/plugins/engine/views/components/multilinetextfield.html +12 -1
  30. package/src/server/plugins/engine/views/components/paymentfield.html +1 -1
  31. package/src/server/plugins/engine/views/partials/preview-banner.html +3 -1
@@ -8,7 +8,9 @@
8
8
  </p>
9
9
  {%- endmacro -%}
10
10
 
11
- {% call govukNotificationBanner() %}
11
+ {% call govukNotificationBanner({
12
+ titleText: t('pages.preview.bannerTitle')
13
+ }) %}
12
14
  {% set previewModeTranslated = t('common.' + previewMode) %}
13
15
  {% if not context.isForceAccess %}
14
16
  <p class="govuk-notification-banner__heading govuk-!-margin-bottom-0">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-engine-plugin",
3
- "version": "5.0.0-alpha.1",
3
+ "version": "5.0.0-alpha.3",
4
4
  "description": "Defra forms engine",
5
5
  "type": "module",
6
6
  "files": [
@@ -6,6 +6,7 @@ import { initPreviewCloseLink as initPreviewCloseLinkImp } from './preview-close
6
6
  export { initMaps } from './map.js'
7
7
  export * as map from './map.js'
8
8
  export * as geospatialMap from './geospatial-map.js'
9
+ export * as sssiDataset from './sssi-dataset.js'
9
10
 
10
11
  export const initAllGovuk = initAllGovukImp
11
12
  export const initAllAutocomplete = initAllAutocompleteImp
@@ -45,6 +45,7 @@ export class PaymentField extends FormComponent {
45
45
  declare options: PaymentFieldComponent['options']
46
46
  declare formSchema: ObjectSchema
47
47
  declare stateSchema: ObjectSchema
48
+ declare def: PaymentFieldComponent
48
49
  isAppendageStateSingleObject = true
49
50
 
50
51
  constructor(
@@ -54,6 +55,7 @@ export class PaymentField extends FormComponent {
54
55
  super(def, props)
55
56
 
56
57
  this.options = def.options
58
+ this.def = def
57
59
 
58
60
  const paymentStateSchema = joi
59
61
  .object({
@@ -110,6 +112,8 @@ export class PaymentField extends FormComponent {
110
112
  getViewModel(context: RenderContext) {
111
113
  const { payload } = context
112
114
  const viewModel = super.getViewModel(context)
115
+ const { translator } = context
116
+ const { tComponent } = translator
113
117
 
114
118
  // Payload is pre-populated from state if a payment has already been made
115
119
  const paymentState = this.isPaymentState(payload[this.name] as unknown)
@@ -124,7 +128,8 @@ export class PaymentField extends FormComponent {
124
128
  return {
125
129
  ...viewModel,
126
130
  amount: formatCurrency(amount),
127
- description: this.options.description,
131
+ description:
132
+ tComponent(this.def, 'paymentDescription') || this.options.description,
128
133
  paymentState
129
134
  }
130
135
  }
@@ -1,4 +1,8 @@
1
- import { type FormDefinition } from '@defra/forms-model'
1
+ import {
2
+ yesNoListNoItemId,
3
+ yesNoListYesItemId,
4
+ type FormDefinition
5
+ } from '@defra/forms-model'
2
6
  import { type i18n } from 'i18next'
3
7
 
4
8
  import { createTranslator } from './createTranslator.js'
@@ -28,6 +32,22 @@ export function loadFormTranslations(def: FormDefinition, i18nInstance: i18n) {
28
32
  if (formTranslations) {
29
33
  for (const [lng, resources] of Object.entries(formTranslations)) {
30
34
  i18nInstance.addResourceBundle(lng, 'form', resources, true, true)
35
+
36
+ // Temporary workaround - until we develop a better solution
37
+ if (lng === 'cy') {
38
+ i18nInstance.addResource(
39
+ lng,
40
+ 'form',
41
+ `listItems.${yesNoListYesItemId}.text`,
42
+ 'Ie'
43
+ )
44
+ i18nInstance.addResource(
45
+ lng,
46
+ 'form',
47
+ `listItems.${yesNoListNoItemId}.text`,
48
+ 'Nage'
49
+ )
50
+ }
31
51
  }
32
52
  }
33
53
  }
@@ -111,6 +111,7 @@
111
111
  "body": "Os hoffech dderbyn e-bost prawf, [[link]] yr hoffech i gyflwyniadau ffurflen fynd iddo.",
112
112
  "linkText": "nodwch y cyfeiriad e-bost (yn agor mewn tab newydd)"
113
113
  },
114
+ "bannerTitle": "Pwysig",
114
115
  "bannerForce": "Rhagolwg o ffurflen [[previewMode]] yw hon. Peidiwch â rhoi gwybodaeth bersonol.",
115
116
  "bannerText": "Dyma ragolwg o dudalen ffurflen [[previewMode]] rydych chi'n ei golygu.",
116
117
  "previousPages": "Mae'n dibynnu ar atebion o dudalennau cynharach yn y ffurflen. Yn y fersiwn fyw, bydd angen i ddefnyddwyr gwblhau'r cwestiynau hynny yn gyntaf."
@@ -220,7 +221,7 @@
220
221
 
221
222
  "yesNoField": {
222
223
  "yes": "Ie",
223
- "no": "Na",
224
+ "no": "Nage",
224
225
  "validation": {
225
226
  "selectYesNoRequired": "{{#label}} - dewiswch ie neu na"
226
227
  }
@@ -245,7 +246,7 @@
245
246
  },
246
247
 
247
248
  "paymentField": {
248
- "detailsRequired": "Angen manylion talu",
249
+ "detailsRequired": "Angen talu",
249
250
  "pendingTransaction": "Mae'n bosibl y gwelwch drafodiad ar y gweill yn eich cyfrif banc ond dim ond pan fyddwch yn cyflwyno'r ffurflen y codir tâl arnoch.",
250
251
  "addPaymentDetails": "Ychwanegu manylion talu",
251
252
  "cannotTakePayment": "Mae problem ac ni allwn dderbyn taliad. Cysylltwch â ni (manylion yn nhroedyn y ffurflen hon) neu cadwch eich cynnydd a dychwelyd at y ffurflen yn ddiweddarach.",
@@ -266,6 +267,19 @@
266
267
  "uploadedFilesHeading": "Ffeiliau a uwchlwythwyd",
267
268
  "filesCount_one": "Uwchlwythwyd [[count]] ffeil",
268
269
  "filesCount_other": "Uwchlwythwyd [[count]] ffeil"
270
+ },
271
+
272
+ "characterCount": {
273
+ "_comment": "Note the use of %{count} instead of [[count]]. This is because we are passing to the govuk template, not passing to Joi",
274
+ "underLimit": {
275
+ "one": "Mae gennych %{count} nod ar ôl",
276
+ "other": "Mae gennych %{count} nod ar ôl"
277
+ },
278
+ "atLimit": "Mae gennych 0 nod ar ôl",
279
+ "overLimit": {
280
+ "one": "Mae gennych %{count} nod yn ormod",
281
+ "other": "Mae gennych %{count} nod yn ormod"
282
+ }
269
283
  }
270
284
  }
271
285
  }
@@ -111,6 +111,7 @@
111
111
  "body": "If you want to receive a test email, [[link]] you want form submissions to go to.",
112
112
  "linkText": "enter the email address (opens in new tab)"
113
113
  },
114
+ "bannerTitle": "Important",
114
115
  "bannerForce": "This is a preview of a [[previewMode]] form. Do not enter personal information.",
115
116
  "bannerText": "This is a preview of a [[previewMode]] form page you are editing.",
116
117
  "previousPages": "It depends on answers from earlier pages in the form. In the live version, users will need to complete those questions first."
@@ -245,7 +246,7 @@
245
246
  },
246
247
 
247
248
  "paymentField": {
248
- "detailsRequired": "Payment details required",
249
+ "detailsRequired": "Payment required",
249
250
  "pendingTransaction": "You may see a pending transaction in your bank account but you will only be charged when you submit the form.",
250
251
  "addPaymentDetails": "Add payment details",
251
252
  "cannotTakePayment": "There is a problem and we cannot take a payment. Contact us (details in the footer of this form) or save your progress and return to the form later.",
@@ -266,6 +267,19 @@
266
267
  "uploadedFilesHeading": "Uploaded files",
267
268
  "filesCount_one": "[[count]] file uploaded",
268
269
  "filesCount_other": "[[count]] files uploaded"
270
+ },
271
+
272
+ "characterCount": {
273
+ "_comment": "Note the use of %{count} instead of [[count]]. This is because we are passing to the govuk template, not passing to Joi",
274
+ "underLimit": {
275
+ "one": "You have %{count} character remaining",
276
+ "other": "You have %{count} characters remaining"
277
+ },
278
+ "atLimit": "You have 0 characters remaining",
279
+ "overLimit": {
280
+ "one": "You have %{count} character too many",
281
+ "other": "You have %{count} characters too many"
282
+ }
269
283
  }
270
284
  }
271
285
  }
@@ -22,6 +22,7 @@ export type FormDefinitionTranslations = Record<
22
22
  hint: string
23
23
  content: string
24
24
  shortDescription: string
25
+ paymentDescription: string
25
26
  }>
26
27
  >
27
28
  sections: Record<string, Partial<Pick<Section, 'title'>>>
@@ -174,9 +174,14 @@ export class QuestionPageController extends PageController {
174
174
  if (!pageTitle) {
175
175
  pageTitle = labelOrLegend.text
176
176
  }
177
- labelOrLegend.text = isOptional
178
- ? `${pageTitle} ${t('common.optional')}`
179
- : pageTitle
177
+
178
+ // The question text may have already appended 'optional' in the relevant language
179
+ const optionalWord = t('common.optional')
180
+ const optionalAlreadyAppended = pageTitle.endsWith(` ${optionalWord}`)
181
+ labelOrLegend.text =
182
+ isOptional && !optionalAlreadyAppended
183
+ ? `${pageTitle} ${optionalWord}`
184
+ : pageTitle
180
185
  }
181
186
 
182
187
  // Fallback if still no pageTitle set
@@ -3,7 +3,18 @@
3
3
 
4
4
  {% macro MultilineTextField(component) %}
5
5
  {% if component.model.isCharacterOrWordCount == true %}
6
- {{ govukCharacterCount(component.model) }}
6
+ {% set characterParams = component.model | merge({
7
+ charactersUnderLimitText: {
8
+ one: t('components.characterCount.underLimit.one'),
9
+ other: t('components.characterCount.underLimit.other')
10
+ },
11
+ charactersAtLimitText: t('components.characterCount.atLimit'),
12
+ charactersOverLimitText: {
13
+ one: t('components.characterCount.overLimit.one'),
14
+ other: t('components.characterCount.overLimit.other')
15
+ }
16
+ } ) %}
17
+ {{ govukCharacterCount(characterParams) }}
7
18
  {% else %}
8
19
  {{ govukTextarea(component.model) }}
9
20
  {% endif %}
@@ -16,7 +16,7 @@
16
16
  <p class="govuk-body">{{ t('components.paymentField.preAuthorisedBody') }}</p>
17
17
  {% else %}
18
18
  {# No pre-authorisation - show payment form #}
19
- <h2 class="govuk-heading-m">{{ model.label.text if model.label and model.label.text else t('components.paymentField.detailsRequired') }}</h2>
19
+ <h2 class="govuk-heading-m">{{ t('components.paymentField.detailsRequired') }}</h2>
20
20
 
21
21
  <p class="govuk-body">{{ description }}</p>
22
22
 
@@ -8,7 +8,9 @@
8
8
  </p>
9
9
  {%- endmacro -%}
10
10
 
11
- {% call govukNotificationBanner() %}
11
+ {% call govukNotificationBanner({
12
+ titleText: t('pages.preview.bannerTitle')
13
+ }) %}
12
14
  {% set previewModeTranslated = t('common.' + previewMode) %}
13
15
  {% if not context.isForceAccess %}
14
16
  <p class="govuk-notification-banner__heading govuk-!-margin-bottom-0">