Skip to content

Commit e0dbe46

Browse files
committed
gw-disable-submission-on-enter.js: Fixed an issue with disable enter snippet not working with Conversational Forms.
1 parent 7e5500f commit e0dbe46

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@
1010
document.addEventListener( 'keydown', function(e) {
1111
var isGravityForm = e.target.closest( '.gform_wrapper' ) !== null;
1212
var code = e.keyCode || e.which;
13-
if ( code == 13 && ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) && isGravityForm ) {
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.
1428
e.stopImmediatePropagation();
1529
e.preventDefault();
1630
}

0 commit comments

Comments
 (0)