LeWolf
(Leon Wolff)
May 24, 2022, 8:48pm
1
Hi,
I’m currently trying to use a form field as an interactive text field, using JS for further shenanigans.
Since I get the values of the form fields without the need for a submission, I’d like to disable the automatic submission.
If I hit enter on a form with only a text field, it automatically sends the form – which I’d like to avoid.
Is there a sensible solution, possibly with Javascript for my problem?
Cheers
Leon
mww
(Milan )
May 25, 2022, 12:28am
2
Hi @LeWolf ,
You could try something like this in Page Settings > Custom Code > Footer Code:
<script>
$('#form').submit(function() {
return false;
});
</script>
You’ll need to replace the form ID in $(‘#form ’).
Let me know how you go! Would be great if you could send read-only link if you need further assistance.
Cheers
LeWolf
(Leon Wolff)
May 25, 2022, 12:53pm
3
Hi @mww ,
thanks for your suggestion!
I placed the code in a Code Embed since I wanted to disable the function for one page rather than the whole project.
Sadly hitting enter still submits the form field.
I recreated a page similar to the one it will be placed on later since I’m not allowed to share the page yet (sorry!).
Here’s the Read Only
mww
(Milan )
May 26, 2022, 3:49am
4
Hi @LeWolf ,
This code should work - paste it in Page Settings > Custom Code > Before </body>
tag:
<script type="text/javascript">
window.addEventListener('keydown',function(e){if(e.keyIdentifier=='U+000A'||e.keyIdentifier=='Enter'||e.keyCode==13){if(e.target.nodeName=='INPUT'&&e.target.type=='text'){e.preventDefault();return false;}}},true);
</script>
Source: javascript - jquery disable form submit on enter - Stack Overflow .
Let me know if this doesn’t work for you!
Cheers
1 Like
LeWolf
(Leon Wolff)
May 28, 2022, 11:46am
5
This worked, thanks a lot!
1 Like