Skip to content

Commit f3cb817

Browse files
authored
gpaa-plus-code.js: Migrated from experimental folder.
1 parent a1c7410 commit f3cb817

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Gravity Perks // GP Address Autocomplete // Display Google Plus Code
3+
* https://gravitywiz.com/documentation/gravity-forms-address-autocomplete/
4+
*
5+
* Experimental Snippet 🧪
6+
*
7+
* Adds a Google Plus Code to the configured text field when an address is autocompleted.
8+
*
9+
* Instructions:
10+
* 1. Install our free Custom JavaScript for Gravity Forms plugin.
11+
* Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
12+
* 2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
13+
* 3. Update the field id variables to match your the address and text fields you would like this to
14+
* apply to.
15+
*/
16+
17+
// update this with the id of the address field you want this to apply to.
18+
var addressFieldId = 1;
19+
// update this with the id of the text field you would like the plus code displayed in.
20+
var plusCodeFieldId = 3;
21+
22+
window.gform.addFilter('gpaa_autocomplete_options', (autocompleteOptions, gpaa, formId, fieldId) => {
23+
if (formId !== 'GFFORMID' && fieldId !== addressFieldId) {
24+
return autocompleteOptions;
25+
}
26+
27+
autocompleteOptions.fields.push('plus_code');
28+
29+
return autocompleteOptions;
30+
});
31+
32+
window.gform.addAction('gpaa_fields_filled', (place, instance) => {
33+
// "plus_code" includes both "global_code" or "compound_code" as documented here: https://developers.google.com/maps/documentation/javascript/reference/places-service#PlacePlusCode
34+
var plusCode = place?.plus_code?.global_code || 'No Plus Code found';
35+
36+
$('#input_GFFORMID_' + plusCodeFieldId).val(plusCode);
37+
});

0 commit comments

Comments
 (0)