Skip to content

Commit 04e48c1

Browse files
Restrict the user to add multiple rows of data when it is a MultiInputField inside a page (#201)
1 parent 95418b9 commit 04e48c1

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

fsd_config/form_jsons/pfn_rp/pfn-rp-payment-profile-and-spend-forecast.json

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@
248248
"customText": {
249249
"samePageTitle": "Capacity funding spend forecast",
250250
"samePageTableItemName": ""
251-
}
251+
},
252+
"maxMultiInputFieldRows": 1
252253
},
253254
"controller": "RepeatingFieldPageController"
254255
},
@@ -402,7 +403,8 @@
402403
"customText": {
403404
"samePageTitle": "Programme delivery funding (capital) spend forecast",
404405
"samePageTableItemName": ""
405-
}
406+
},
407+
"maxMultiInputFieldRows": 1
406408
},
407409
"controller": "RepeatingFieldPageController"
408410
},
@@ -555,7 +557,8 @@
555557
"customText": {
556558
"samePageTitle": "Programme delivery funding (revenue) spend forecast",
557559
"samePageTableItemName": ""
558-
}
560+
},
561+
"maxMultiInputFieldRows": 1
559562
},
560563
"controller": "RepeatingFieldPageController"
561564
},
@@ -706,7 +709,8 @@
706709
"customText": {
707710
"samePageTitle": "Pre-approved interventions spend forecast (Year 1)",
708711
"samePageTableItemName": ""
709-
}
712+
},
713+
"maxMultiInputFieldRows": 1
710714
},
711715
"controller": "RepeatingFieldPageController"
712716
},
@@ -837,7 +841,8 @@
837841
"customText": {
838842
"samePageTitle": "Pre-approved interventions spend forecast (Year 2)",
839843
"samePageTableItemName": ""
840-
}
844+
},
845+
"maxMultiInputFieldRows": 1
841846
},
842847
"controller": "RepeatingFieldPageController"
843848
},
@@ -968,7 +973,8 @@
968973
"customText": {
969974
"samePageTitle": "Pre-approved interventions spend forecast (Year 3)",
970975
"samePageTableItemName": ""
971-
}
976+
},
977+
"maxMultiInputFieldRows": 1
972978
},
973979
"controller": "RepeatingFieldPageController"
974980
},
@@ -1099,7 +1105,8 @@
10991105
"customText": {
11001106
"samePageTitle": "Pre-approved interventions spend forecast (Year 4)",
11011107
"samePageTableItemName": ""
1102-
}
1108+
},
1109+
"maxMultiInputFieldRows": 1
11031110
},
11041111
"controller": "RepeatingFieldPageController"
11051112
},
@@ -1186,7 +1193,8 @@
11861193
"customText": {
11871194
"samePageTitle": "Off-menu interventions spend forecast",
11881195
"samePageTableItemName": ""
1189-
}
1196+
},
1197+
"maxMultiInputFieldRows": 1
11901198
},
11911199
"controller": "RepeatingFieldPageController"
11921200
},
@@ -1273,7 +1281,8 @@
12731281
"customText": {
12741282
"samePageTitle": "Management costs spend forecast",
12751283
"samePageTableItemName": ""
1276-
}
1284+
},
1285+
"maxMultiInputFieldRows": 1
12771286
},
12781287
"controller": "RepeatingFieldPageController"
12791288
},
@@ -1361,7 +1370,8 @@
13611370
"customText": {
13621371
"samePageTitle": "Unknown uses of funding forecast",
13631372
"samePageTableItemName": ""
1364-
}
1373+
},
1374+
"maxMultiInputFieldRows": 1
13651375
},
13661376
"controller": "RepeatingFieldPageController"
13671377
}
@@ -1391,4 +1401,4 @@
13911401
"url": ""
13921402
},
13931403
"phaseBanner": {}
1394-
}
1404+
}

runner/src/server/plugins/engine/views/partials/form.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@
55
<input type="hidden" name="crumb" value="{{ crumb }}"/>
66

77
{% if page.isRepeatingFieldPageController and details %}
8-
{{ componentList(components) }}
9-
{{ govukButton({
10-
attributes: { id: "add-another"},
11-
classes: "govuk-button govuk-button--secondary",
12-
text: page.saveText
13-
}) }}
8+
{# maxMultiInputFieldRows allow the users to control how many data rows that can be added in MultiInputField component in a page #}
9+
{% if not page.options.maxMultiInputFieldRows or not details.rows.length or page.options.maxMultiInputFieldRows > details.rows.length %}
10+
{{ componentList(components) }}
11+
{{ govukButton({
12+
attributes: { id: "add-another" },
13+
classes: "govuk-button govuk-button--secondary",
14+
text: page.saveText
15+
}) }}
16+
{% else %}
17+
{% set filteredComponents = [] %}
18+
{% for component in components %}
19+
{% if component.type != "MultiInputField" %}
20+
{% set _ = filteredComponents.push(component) %}
21+
{% endif %}
22+
{% endfor %}
23+
{{ componentList(filteredComponents) }}
24+
{% endif %}
1425
{% if page.options.customText.samePageTitle %}
1526
<table class="govuk-table">
1627
<caption

0 commit comments

Comments
 (0)