I am looking for help with some JavaScript in the Forms Modern Designer. It is supposed to append table rows form a date range selection. I am new to JavaScript but I don't see a mention to the date range selection in the JavaScript provided.
JavaScript:
const updateTableRows = async (tableFieldId, rowCount) => {
const currentTableFieldValues = LFForm.getFieldValues(tableFieldId);
const curRowCount = currentTableFieldValues.length;
if (curRowCount < rowCount) {
await LFForm.addRow(tableFieldId, rowCount - curRowCount);
} else if (curRowCount > rowCount) {
await LFForm.deleteRow(
tableFieldId,
...Array.from(Array(curRowCount - rowCount)).map(
(_, i) => curRowCount - i - 1
)
);
}
};
let lastFieldValue = null;
LFForm.onFieldChange(
async () => {
const fieldValues = LFForm.getFieldValues({ fieldId: 31});
// Check if the field value has changed since the last time a row was added
if (fieldValues !== lastFieldValue) {
// Update the table rows with the new row count
await updateTableRows({ variableName: 'Date_Time' }, fieldValues);
lastFieldValue = fieldValues; // Update the last field value
}
},
{ fieldId: 31}
);
Screenshot:
Form: