I figured out a way to reject a form in the new designer while bypassing required fields - with code only!
No field rules required so it is super easy to add this to a new form!
/*Bypass required fields on form reject by user.
The reqFields array is declared outside the function so that it carries across multiple submission attempts.
If the Reject button is used, the required validation of the fields is removed, even if the submission fails
for another reason.
However, another submission attempt (non-Reject) will reinstate the required validation of those fields
based on what is carried over in the reqFields array from the prior Reject submission attempt.*/
var reqFields = [];
LFForm.onFormSubmission(async function (event) {
const userAction = event.data.action.value;
if (userAction == 'Reject') {
reqFields = LFForm.findFields(f => f.settings.required);
for (const e of reqFields) {
await LFForm.validateFields(e, {"required": false});
}
}
else {
for (const e of reqFields) {
await LFForm.validateFields(e, {"required": true});
}
}
});
EDIT: Based on feedback from Zac St. Louis, I removed the await keyword from line 11 because the LFForm.findFields function runs synchronously.
EDIT AGAIN: Modified code with more feedback from Zac St. Louis. Rather than looping through the array, it verifies the array isn't empty and passes the whole array to the LFForm.validateFields function, so that improves functionality. Also addresses some edge cases around the initial Reject submission failing (for a different reason than required fields) and ensuring the required fields are reapplied before any other submissions.
/*Bypass required fields on form reject by user.
The reqFields array is declared outside the function so that it carries across multiple submission attempts.
If the Reject button is used, the required validation of the fields is removed, even if the submission fails
for another reason.
However, another submission attempt (non-Reject) will reinstate the required validation of those fields
based on what is carried over in the reqFields array from the prior Reject submission attempt.*/
let reqFields = [];
LFForm.onFormSubmission(async function (event) {
const userAction = event.data.action.value;
if (userAction == 'Reject') {
reqFields = LFForm.findFields(f => f.settings.required);
if (reqFields.length > 0) {
await LFForm.validateFields(reqFields, { "required": false });
}
}
else {
const stillReq = LFForm.findFields(f => f.settings.required).filter((f) => reqFields.findIndex(rf => rf.fieldId === f.fieldId) === -1);
const allReq = reqFields.concat(stillReq);
if (allReq.length > 0) {
await LFForm.validateFields(allReq, { "required": true });
}
}
});