It's possible with tables, I would imagine it's possible with collections as well with some modifications.
Apologies, I don't have time to rework my code to make it work for collections, but here's the Javascript I'm using to change the number of rows in a table based on the value entered in another field:
// Allocate Blocked Tickets Section Populate Table Rows
const updateTable1Rows = async (tableFieldId, rowCount) => {
const currentTable1FieldValues = LFForm.getFieldValues(tableFieldId);
const curRowCount1 = currentTable1FieldValues.length;
if (curRowCount1 < rowCount) {
await LFForm.addRow(tableFieldId, rowCount - curRowCount1);
} else if (curRowCount1 > rowCount) {
await LFForm.deleteRow(
tableFieldId,
...Array.from(Array(curRowCount1 - rowCount)).map(
(_, i) => curRowCount1 - i - 1
)
);
}
};
let lastFieldValue1 = null;
LFForm.onFieldChange(
async () => {
const fieldValues1 = LFForm.getFieldValues({ fieldId: 56 });
// Check if the field value has changed since the last time a row was added
if (fieldValues1[0] !== lastFieldValue1) {
// Update the table rows with the new row count
await updateTable1Rows({ variableName: 'FT_Allocate_Passengers' }, fieldValues1);
lastFieldValue1 = fieldValues1; // Update the last field value
}
},
{ fieldId: 56 }
);
Hopefully it gives you a head start, or someone else can chime in and make the necessary adjustments for you.
Also just to add - I'm using the modern designer in Cloud, so there might need to be extra modifications due to that, although I'm not sure if that's the case or not.
Good luck!