Skip to content

Commit 4ef28ee

Browse files
committed
FLS-1423 - Backend validation in Runner for multi-input field row limit
1 parent 3a8a042 commit 4ef28ee

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

runner/src/server/plugins/engine/page-controllers/RepeatingFieldPageController.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@ export class RepeatingFieldPageController extends PageController {
126126
return parentSchema;
127127
}
128128

129+
async validateComponentFunctions(request, viewModel) {
130+
let errors = await super.validateComponentFunctions(request, viewModel);
131+
const maxRows = this.inputComponent.options?.maxMultiInputFieldRows;
132+
if (maxRows) {
133+
const {adapterCacheService} = request.services([]);
134+
const state = await adapterCacheService.getState(request);
135+
const currentRows = this.getPartialState(state) || [];
136+
if (currentRows.length >= maxRows) {
137+
const rowText = maxRows === 1 ? "row" : "rows";
138+
errors.push({
139+
path: this.inputComponent.name,
140+
name: this.inputComponent.name,
141+
text: `You cannot add more than ${maxRows} ${rowText}`,
142+
});
143+
}
144+
}
145+
146+
return errors;
147+
}
148+
129149
makeGetRouteHandler() {
130150
return async (request: HapiRequest, h: HapiResponseToolkit) => {
131151
const {query} = request;

0 commit comments

Comments
 (0)