Skip to content

Commit 9c32b47

Browse files
authored
gw-disable-submission-on-enter.js: Fixed an issue with disable enter snippet not working with Conversational Forms.
1 parent 4beb163 commit 9c32b47

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

gravity-forms/gw-disable-submission-on-enter.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,25 @@
77
* Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
88
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
99
*/
10-
jQuery(document).on( 'keypress', '.gform_wrapper', function (e) {
11-
var code = e.keyCode || e.which;
12-
if ( code == 13 && ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) {
13-
e.preventDefault();
14-
return false;
15-
}
16-
} );
10+
document.addEventListener( 'keydown', function(e) {
11+
var isGravityForm = e.target.closest( '.gform_wrapper' ) !== null;
12+
var code = e.keyCode || e.which;
13+
if ( code == 13 && isGravityForm ) {
14+
var isTextarea = e.target.tagName.toLowerCase() === 'textarea';
15+
var isSubmitOrButton = jQuery(e.target).is('input[type="submit"], input[type="button"]');
16+
17+
// Allow default for submit/buttons.
18+
if (isSubmitOrButton) {
19+
return;
20+
}
21+
22+
// Allow Shift+Enter in textarea for line breaks.
23+
if (isTextarea && e.shiftKey) {
24+
return;
25+
}
26+
27+
// Block everything else.
28+
e.stopImmediatePropagation();
29+
e.preventDefault();
30+
}
31+
}, true );

0 commit comments

Comments
 (0)