Skip to content

Commit 3a8a042

Browse files
committed
FLS-1423 - Allowing multi-input row limit to be set in Designer
1 parent cf94531 commit 3a8a042

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

designer/client/components/multiinput-field-edit/MultiInputFieldEdit.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ enum MultiInputFieldAction {
4242
EDIT_OPTIONS_HIDE_ROW_TITLE = "EDIT_OPTIONS_HIDE_ROW_TITLE",
4343
EDIT_OPTIONS_SHOW_TABLE_TITLE = "EDIT_OPTIONS_SHOW_TABLE_TITLE",
4444
EDIT_OPTIONS_SHOW_TABLE_ITEM_NAME = "EDIT_OPTIONS_SHOW_TABLE_ITEM_NAME",
45+
EDIT_MAX_MULTI_INPUT_FIELD_ROWS = "EDIT_MAX_MULTI_INPUT_FIELD_ROWS",
4546
}
4647

4748
export const MultiInputFieldEdit: any = ({context = AdapterComponentContext}) => {
@@ -92,6 +93,9 @@ export const MultiInputFieldEdit: any = ({context = AdapterComponentContext}) =>
9293
const [tableTitles, setTableTitles] = useState<string[]>(options.columnTitles ? options.columnTitles : []);
9394

9495
const [showEditor, setShowEditor] = useState(false);
96+
97+
const [maxRows, setMaxRows] = useState<string>(selectedComponent.options?.maxMultiInputFieldRows?.toString() || "");
98+
9599
const subComponentRef = useRef(null);
96100

97101
const toggleShowEditor = () => {
@@ -622,6 +626,14 @@ export const MultiInputFieldEdit: any = ({context = AdapterComponentContext}) =>
622626
}
623627
})
624628
}
629+
if (e.type === MultiInputFieldAction.EDIT_MAX_MULTI_INPUT_FIELD_ROWS) {
630+
setMaxRows(e.payload);
631+
const numValue = parseInt(e.payload);
632+
if (!selectedComponent.options) {
633+
selectedComponent.options = {};
634+
}
635+
selectedComponent.options.maxMultiInputFieldRows = isNaN(numValue) || numValue <= 0 ? undefined : numValue;
636+
}
625637
}
626638

627639
const renderSelectedSubComponentConfigEdit = () => {
@@ -932,6 +944,26 @@ export const MultiInputFieldEdit: any = ({context = AdapterComponentContext}) =>
932944
children: ["Table Item Name"]
933945
}}/>
934946
</div>
947+
948+
<div className="govuk-form-group" data-test-id="max-multi-input-field-rows-wrapper">
949+
<Input id="max-multi-input-field-rows" name="maxMultiInputFieldRows"
950+
onChange={(e) =>
951+
handleData({
952+
type: MultiInputFieldAction.EDIT_MAX_MULTI_INPUT_FIELD_ROWS,
953+
payload: e.target.value,
954+
})
955+
}
956+
value={maxRows}
957+
type="number"
958+
label={{
959+
className: "govuk-label--s",
960+
children: ["Maximum number of rows"]
961+
}}
962+
hint={{
963+
children: ["Set the maximum number of rows users can add. Leave empty for unlimited rows."]
964+
}}/>
965+
</div>
966+
935967
<div className="govuk-label govuk-label--s">----- Sub Components list -----</div>
936968
<div className="govuk-form-group">
937969
<label className="govuk-label govuk-label--s" htmlFor="select-field-types">

e2e-test/cypress/e2e/designer/multiInputFieldEdit.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,21 @@ Feature: Multi Input Field Edit
140140
| YesNoField | This is a yes no field | |
141141
| MonthYearField | This is a month field | {"items": [{"name": "Month"},{"name": "Year"}]} |
142142
| MultilineTextField | This is a multiline field | |
143+
144+
Scenario: Test multi input field with maximum rows configuration
145+
And I continue create a component
146+
| page | component | title |
147+
| First page | Multi Input Field | Which eggs do you like? |
148+
And I add table title name "MaxRowsTest"
149+
And I configure maximum rows as "2"
150+
And I add child components
151+
| component | title | options | additional | listItem | name |
152+
| TextField | Item name | {} | false | | itemname |
153+
And I save component
154+
And I preview the page "First page" without href
155+
When I enter "First item" for "Item name"
156+
And I click "Save and add another"
157+
When I enter "Second item" for "Item name"
158+
And I click "Save and add another"
159+
Then I should not see the "Save and add another" button
160+
And I should see the "Save and continue" button
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { When, Then } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
When("I configure maximum rows as {string}", (maxRows) => {
4+
cy.get("#max-multi-input-field-rows").type(maxRows);
5+
});
6+
7+
When("I click {string}", (buttonText) => {
8+
cy.findByRole("button", { name: buttonText }).click();
9+
});
10+
11+
Then("I should not see the {string} button", (buttonText) => {
12+
cy.findByRole("button", { name: buttonText }).should('not.exist');
13+
});
14+
15+
Then("I should see the {string} button", (buttonText) => {
16+
cy.findByRole("button", { name: buttonText }).should('exist');
17+
});

0 commit comments

Comments
 (0)