Overriding forms to submit via AJAX, but AJAX success event is not dispatched #460
-
Basically, when a form's success behavior is "redirect-return-url" in the form builder but you programmatically enable AJAX, Freeform does not emit all of the AJAX events. I am forcing all forms to submit via AJAX by modifying the form.addEventListener('freeform-ready', (event) => {
event.options.ajax = true;
}); Then, I want to perform various operations after a form has been successfully posted. But, the order of operations in the plugin's _onSubmitAjax = (event) => {
// ...
if (finished && response.onSuccess === SUCCESS_BEHAVIOUR_REDIRECT_RETURN_URL && returnUrl) {
window.location.href = returnUrl;
return;
}
// ...
this._dispatchEvent(EventTypes.EVENT_AJAX_SUCCESS, { request, response });
}; I could update all forms in the form builder to use a different success behavior, but that would be obscure and error prone. Besides, I want the client to continue building forms using whichever success behavior they'd like — I just need to execute code for various integrations/features only when a form submission is successful. If there were a way I could override the success behavior before the request is made, my forms wouldn't meet that conditional shown above and then I redirect the user myself in the I couldn't find a way to do this, though. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Re-reading the docs with fresh eyes, I see this note about the Success Behavior setting on the Form Builder page:
But I cannot find anything in the docs that describes how this can be overridden. What am I missing? |
Beta Was this translation helpful? Give feedback.
-
Hi @chrismlusk, Please see my response to the other question here: If you continue to need assistance with this issue you initially mentioned, please let me know. 🙂 |
Beta Was this translation helpful? Give feedback.
Hi @chrismlusk,
Please see my response to the other question here:
#465 (comment)
If you continue to need assistance with this issue you initially mentioned, please let me know. 🙂