Skip to content

Conversation

@calum-ukhsa
Copy link
Contributor

@calum-ukhsa calum-ukhsa commented Jan 26, 2026

This is an incomplete solution for allowing repeating sections of data, not just repeating single fields. To test this, use the attached JSON form:
looping-textfield.json

/**
* RepeatingSectionSummaryPageController is for pages summarising a set of sections
*/
export class RepeatingSectionSummaryPageController extends PageController {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to coordinate with all UKHSA teams using this type of form if you're replacing this page controller completely or rewrite this as a non-breaking change. (Might be fine - just a warning!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No teams are using this controller other than mine :)

getPartialState!: RepeatingFieldPageController["getPartialState"];
options!: RepeatingFieldPageController["options"];
removeAtIndex!: RepeatingFieldPageController["removeAtIndex"];
hideRowTitles!: RepeatingFieldPageController["hideRowTitles"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assume just shortcutting types here for ease whilst you prototype?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all of these types will be needed, so some will be removed

isRepeatingFieldPageController = true;
isSamePageDisplayMode: boolean;
isSeparateDisplayMode: boolean;
isRepeatingSection: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RepeatingFieldPageController is just intended to repeat a single field multiple times (i.e. 1 page which has 1 field that repeats). Has this option been added to RepeatingFieldPageController to allow recursive repeating fields?

Copy link
Contributor Author

@calum-ukhsa calum-ukhsa Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution utilises existing RepeatingFieldPageController functionality - see/test out the attached form to get an idea of how it all comes together

delete request.payload['crumb'];
const sectionName = this.section.name;
const newObj = {};
newObj[sectionName + 'Container'] = [request.payload];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is + 'Container' needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See/test out the attached form to get an idea of how it all comes together

makePostRouteHandler() {
return async (request: HapiRequest, h: HapiResponseToolkit) => {
const modifyUpdate = () => {
delete request.payload['crumb'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the csrf cookie needed to be deleted? I would also just be careful about using delete in general, since it would mutate request.payload directly. It might be safe in this instance but can cause non-obvious side-effects with how js handles objects (by reference)

If you need the payload without the csrf cookie - do something like this

const { crumb, ...payload } = request;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed so that the payload object is cloned before the crumb is removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants