Disable Submission when Pressing Enter

Instructions

  1. Install our free Custom Javascript for Gravity Forms plugin. Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
  2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
Read the Walkthrough

Code

Filename: gw-disable-submission-on-enter.js

/**
 * Gravity Wiz // Gravity Forms // Disable Submission when Pressing Enter
 * https://gravitywiz.com/disable-submission-when-pressing-enter-for-gravity-forms/
 *
 * Instructions:
 * 1. Install our free Custom Javascript for Gravity Forms plugin.
 * Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 * 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 */
document.addEventListener( 'keydown', function(e) {
	var isGravityForm = e.target.closest( '.gform_wrapper' ) !== null;
	var code = e.keyCode || e.which;
	if ( code == 13 && isGravityForm ) {
		var isTextarea = e.target.tagName.toLowerCase() === 'textarea';
		var isSubmitOrButton = jQuery(e.target).is('input[type="submit"], input[type="button"]');

		// Allow default for submit/buttons.
		if (isSubmitOrButton) {
			return;
		}

		// Allow Shift+Enter in textarea for line breaks.
		if (isTextarea && e.shiftKey) {
			return;
		}

		// Block everything else.
		e.stopImmediatePropagation();
		e.preventDefault();
	}
}, true );

Comments

  1. Laurence Lee
    Laurence Lee May 7, 2025 at 2:21 pm

    Hello, is there any way to achive this while using the Gravity Forms Conversational Forms add on? The current snippet doesn’t seem to work with Conversational Forms. Thanks!

    Reply
    1. Roxy Stoltz
      Roxy Stoltz Staff May 8, 2025 at 4:48 am

      Hey Laurence,

      You’re right! I’ve tested this locally and it indeed looks like it doesn’t work with the Gravity Forms Conversational Forms Add-on. I’ve submitted a feature request to look at possibly updating the snippet to support this. 🙂

    2. Saif Sultan
      Saif Sultan Staff May 16, 2025 at 12:41 pm

      Hey Laurence,

      We have officially updated the snippet with full support for Gravity Forms Conversational Forms added.

      We hope that helps!

      Best,

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.