I have an old website with JQuery 1.7 which works correctly till two days ago. Suddenly some of my buttons do not work anymore and, after clicking on them, I get this warning in the console:
Form submission canceled because the form is not connected
The code behind the click is something like this:
this.handleExcelExporter = function(href, cols) {
var form = $('<form method="post"><input type="submit" /><input type="hidden" name="layout" /></form>').attr('action', href);
$('input[name="layout"]', form).val(JSON.stringify(cols));
$('input[type="submit"]', form).click();
}
It seems that Chrome 56 doesn't support this kind of code anymore. Isn't it? If yes my question is:
- Why did this happened suddenly? Without any deprecation warning?
- What is the workaround for this code?
- Is there a way to force chrome (or other browsers) to work like before without changing any code?
P.S. It doesn't work in the latest firefox version either (without any message). Also it does not work in IE 11.0 & Edge! (both without any message)
You must ensure that the form is in the document. You can append the form to the body.
if you are seeing this error in React JS when you try to submit the form by pressing enter, make sure all your buttons in the form that do not submit the form have a
type="button"
.If you have only one
button
withtype="submit"
pressing Enter will submit the form as expected.References:
https://dzello.com/blog/2017/02/19/demystifying-enter-key-submission-react-forms-multiple-buttons/ https://github.com/facebook/react/issues/2093
I faced the same issue in one of our implementation.
we were using jquery.forms.js. which is a forms plugin and available here. http://malsup.com/jquery/form/
we used the same answer provided above and pasted
and it worked.Thanks.
A thing to look out for if you see this in React, is that the
<form>
still has to render in the DOM while it's submitting. i.e, this will failSo when the form is submitted,
state.submitting
gets set and the "submitting..." message renders instead of the form, then this error happens.Moving the form tag outside the conditional ensured that it was always there when needed, i.e.