Skip to content

Commit aa60b3a

Browse files
authored
gppa-wait-for-population-on-enter-press.js: Added a new snippet.
1 parent 8faffab commit aa60b3a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Gravity Perks // Populate Anything // Wait for Population Before Submitting When Enter Key Pressed
3+
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/
4+
*
5+
* By default, the form is immediately submitted after the Enter key is pressed. This means if the field triggers
6+
* dynamic population of other fields via Populate Anything, that population will not occur before the form is submitted.
7+
*
8+
* This snippet allows to to specify trigger fields that should wait for Populate Anything to finish populating before
9+
* allowing the Enter-keypress-triggered submission from continuing.
10+
*
11+
* Instructions:
12+
*
13+
* 1. Install this snippet with our free Custom JavaScript plugin.
14+
* https://gravitywiz.com/gravity-forms-custom-javascript/
15+
*
16+
* 2. Add "gppa-wait-for-pop" to the CSS Class Name setting for field that will trigger the population.
17+
*/
18+
$( document ).on( 'keypress', '.gppa-wait-for-pop', function( e ) {
19+
var code = e.keyCode || e.which;
20+
if ( code != 13 || $( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) {
21+
return true;
22+
}
23+
e.preventDefault();
24+
$( document )
25+
.off( 'gppa_updated_batch_fields.gpqr' )
26+
.on( 'gppa_updated_batch_fields.gpqr', function( event, formId ) {
27+
setTimeout( function() {
28+
$( '#gform_{0}'.format( formId ) ).submit();
29+
} );
30+
} );
31+
return false;
32+
} );

0 commit comments

Comments
 (0)