Form events
A custom event named send2crmFormSending
is raised on the form element immediately prior to sending a form submission. This can be used to modify the data sent.
let form = document.querySelector('form#myform');
form.addEventListener('send2crmFormSending', (event) => {
// The event.detail property contains the form data to be submitted.
let formData = event.detail;
// Add a field value before sending.
formData.values.myconstantvalue = 'data';
// The form submission may be cancelled by setting isSuccess = false.
//formData.isSuccess = false;
// Goals can be added; these will only be applied if the submission is successful.
formData.goals['MYGOAL'] = 10;
});
A custom event named send2crmFormSubmit
is also raised on the form element after submission so you can handle the result.
let form = document.querySelector('form#myform');
form.addEventListener('send2crmFormSubmit', (event) => {
// The event.detail property contains the submitted form data.
// In particular, this includes 'isSuccess', 'error' and 'values' properties.
let formData = event.detail;
if (!formData.isSuccess) {
alert('Submission failed: ' + formData.error, formData.values);
}
});
These events enable bubbling so you can handle them on parent elements including document
or window
.