I'm testing JavaScript in the modern Forms designer. The following script mostly works:\
et lastFieldValue = null;
LFForm.onFieldChange(() => {
const fieldValues = LFForm.getFieldValues({ fieldId: 51 });
// Check if the field value has changed since the last time a row was added
if (fieldValues[0] !== lastFieldValue) {
LFForm.addRow({ variableName: "tbl_perDiem" }, fieldValues);
lastFieldValue = fieldValues[0]; // Update the last field value
}
}, { fieldId: 51 });
I have two date fields and a hidden field (fieldId: 51) that calculates the date difference of my two date fields. This value is used to populate the correct number of rows in my table based on the number of days of a trip.
Currently, any change to the hidden field value adds that number of rows to the existing rows, I would like to add logic that clears existing rows in the table and repopulates it with the correct number of rows based on the updated hidden field value. Is that possible in the modern designer? Any suggestions would be appreciated
Example of what I'm seeing:
First attempt is correct
Updating date range results in too many rows: