diff --git a/src/main/modules/nunjucks/index.ts b/src/main/modules/nunjucks/index.ts index 945cf9709f..6314f49d52 100644 --- a/src/main/modules/nunjucks/index.ts +++ b/src/main/modules/nunjucks/index.ts @@ -66,47 +66,57 @@ export class Nunjucks { }); env.addGlobal('formItems', function (items: FormInput[], userAnswer: string | Record) { - return items.map(i => ({ - id: i.id, - text: this.env.globals.getContent.call(this, i.label), - name: i.name, - classes: i.classes, - disabled: i.disabled, - value: i.value ?? userAnswer?.[i.name as string] ?? (userAnswer as string), - attributes: i.attributes, - checked: i.selected ?? userAnswer?.[i.name as string]?.includes(i.value as string) ?? i.value === userAnswer, - hint: i.hint && { - html: this.env.globals.getContent.call(this, i.hint), - }, - //divider: this.env.globals.getContent.call(this, i.divider), - divider: - typeof i.divider === 'function' ? this.env.globals.getContent.call(this, i.divider) : i.divider && 'or', - behaviour: (i.exclusive && 'exclusive') || this.env.globals.getContent.call(this, i.behaviour), - open: i.open, - conditional: (() => { - if (i.warning) { - return { - html: env.render(`${__dirname}/../../steps/common/error/warning.njk`, { - message: this.env.globals.getContent.call(this, i.warning), - warning: this.ctx.warning, - }), - }; - } else if (i.conditionalText) { - return { - html: this.env.globals.getContent.call(this, i.conditionalText), - }; - } else if (i.subFields) { - return { - html: env.render(`${__dirname}/../../steps/common/form/fields.njk`, { - ...this.ctx, - form: { fields: i.subFields }, - }), - }; - } else { - return undefined; - } - })(), - })); + return items.map(i => { + const itemConfig = { + id: i.id, + text: this.env.globals.getContent.call(this, i.label), + name: i.name, + classes: i.classes, + disabled: i.disabled, + value: i.value ?? userAnswer?.[i.name as string] ?? (userAnswer as string), + attributes: i.attributes, + checked: i.selected ?? userAnswer?.[i.name as string]?.includes(i.value as string) ?? i.value === userAnswer, + hint: i.hint && { + html: this.env.globals.getContent.call(this, i.hint), + }, + //divider: this.env.globals.getContent.call(this, i.divider), + divider: + typeof i.divider === 'function' ? this.env.globals.getContent.call(this, i.divider) : i.divider && 'or', + behaviour: (i.exclusive && 'exclusive') || this.env.globals.getContent.call(this, i.behaviour), + open: i.open, + conditional: (() => { + if (i.warning) { + return { + html: env.render(`${__dirname}/../../steps/common/error/warning.njk`, { + message: this.env.globals.getContent.call(this, i.warning), + warning: this.ctx.warning, + }), + }; + } else if (i.conditionalText) { + return { + html: this.env.globals.getContent.call(this, i.conditionalText), + }; + } else if (i.subFields) { + return { + html: env.render(`${__dirname}/../../steps/common/form/fields.njk`, { + ...this.ctx, + form: { fields: i.subFields }, + }), + }; + } else { + return undefined; + } + })(), + }; + + if (i.name && ['day', 'month', 'year'].includes(i.name)) { + Object.assign(itemConfig, { + label: this.env.globals.getContent.call(this, i.label), + }); + } + + return itemConfig; + }); }); env.addGlobal('summaryDetailsHtml', function (subFields: FormInput) { diff --git a/src/main/steps/c100-rebuild/applicant/personal-details/content.ts b/src/main/steps/c100-rebuild/applicant/personal-details/content.ts index fe31400a04..642e808cac 100644 --- a/src/main/steps/c100-rebuild/applicant/personal-details/content.ts +++ b/src/main/steps/c100-rebuild/applicant/personal-details/content.ts @@ -226,16 +226,14 @@ export const generateFormFields = (personalDetails: C100Applicant['personalDetai attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, }, { - //label: l => l.dateFormat['month'], - label: l => l.month, + label: l => l.dateFormat['month'], name: 'month', value: dateOfBirth!.month, classes: 'govuk-input--width-2', attributes: { maxLength: 2, pattern: '[0-9]*', inputMode: 'numeric' }, }, { - //label: l => l.dateFormat['year'], - label: l => l.year, + label: l => l.dateFormat['year'], name: 'year', value: dateOfBirth!.year, classes: 'govuk-input--width-4',