File tree Expand file tree Collapse file tree 1 file changed +22
-7
lines changed Expand file tree Collapse file tree 1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change 7
7
* Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
8
8
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
9
9
*/
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 ) ;
You can’t perform that action at this time.
0 commit comments