Jump to content

Disable "enter' in a form to stop it submitting form

Recommended Posts

On 3/26/2021 at 11:38 PM, amiem said:

Hi there!

Im wondering if anyone could help me!!?

I am trying to find a way to stop the form submitting when you press enter / return when filling out the text boxes?

Any help much appreciated!

Thanks!

Simple jquery can help

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>
$(document).ready(function() {
	$('.sqs-block-form').on('keypress keydown keyup', function(e){
       if(e.keyCode == 13) { e.preventDefault(); }
    });
});
</script>

 

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment
  • 9 months later...

@tuanphan @bangank36 

I'm hoping you can further help me with the same issue. In my Squarespace 7.1 website form, I want the enter / return button to simply act as a tab keystroke to allow my audience to put in a list of names into a text field without prematurely submitting the form. I used the code you suggested above but it resulted in fully disabling the enter/return button. Do you have any suggestions on how to modify the code? Thanks!

Link to comment
  • 2 years later...

I want this for a search-entry field. I only want people to select from the preview results and not to go to the search result page. The enter button is the trigger for the search result page.
I think this would be a good solution, but I seem nog to get this code to work.
Could you help me out?

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.