The onbefore instances can be resolved as true/false. If the promise is resolved as false the action (next step / submit) will be cancelled.
The normal instance of excludeField will be the following:
formsApi.onBeforeNextStep((from, to, prevBtn, nextBtn)=> {
prevBtn.disabled = true;
nextBtn.disabled = true;
nextBtn.textContent = 'loading..';
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(true)
}, 2000);
});
});
Often used to make external calls for validation, can also be used to submit the form data outside of a webhook (documents can not be included in these cases).
formsApi.onBeforeSubmit(function() {
alert('Will wait 5 seconds before submitting.');
//Can be used to validate that the forms is allowed to be submitted.
//Often used togheter with formsApi.http
return new Promise(function(resolve, reject) {
resolve(false);
});
});
Example of external call for verification.
formsApi.onBeforeSubmit(() => {
return new Promise((resolve, reject) => {
this.http({
method: 'post',
url: 'https://externalsystem.com/verify/',
data: {
form_data: formsApi.formData,
}
}).then((response) => {
if (response.status === 200) {
resolve(true);
} else {
resolve(false);
}
}).catch((e) => {
resolve(false);
});
});
});