I have read this submit a rails remote form with javascript
and none of the solutions seem to work. I just need to run a callback before the submit gets called.
View
<form id="formA" " novalidate="novalidate" action="https://www.demo.com/form.php" accept-charset="UTF-8" data-remote="true" method="post" _lpchecked="1">
...
</form>
JS
var form = document.forms.item(0)
form.addEventListener('submit', async function(e) {
e.stopImmediatePropagation()
e.preventDefault();
...
form.submit()
});
My form does not seem to submit with remote: true, so no ajax, I get a html response instead of a js response.
It may be too late to answer, but I solved same issue with this code.
It is from : https://stackoverflow.com/a/52304806/1529453