Skip to content

Commit 4bfeb33

Browse files
authored
gpaa-single-line-as-input.php: Added full address capability to the Single Line as Input functionality. (#818)
1 parent 7ab4cbf commit 4bfeb33

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

gp-address-autocomplete/gpaa-single-line-as-input.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Use a Single Line Text field as autocomplete input and populate the Single Line Text field with the full address.
99
*
10-
* Note: This snippet will require the user to make a selection from the auto-suggested addresses.
10+
* Note: This snippet will require the user to make a selection from the auto-suggested addresses.
1111
*
1212
* Plugin Name: GP Address Autocomplete - Use Single Line Text field as Autocomplete Input
1313
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-address-autocomplete/
@@ -60,7 +60,14 @@ public function output_script() {
6060

6161
gform.addFilter('gpaa_values', function (values, place, gpaa, formId, fieldId) {
6262
if ( args.formId == formId && args.addressFieldId == fieldId ) {
63-
values.autocomplete = place.formatted_address;
63+
if ( args.useFullAddress ) {
64+
// Logic borrowed from https://github.com/gravitywiz/snippet-library/pull/730
65+
var fullAddress = gpaa.inputs.autocomplete.value;
66+
values.autocomplete = fullAddress;
67+
values.address1 = fullAddress.split(',')[0].trim();
68+
} else {
69+
values.autocomplete = place.formatted_address;
70+
}
6471
$input.data('gpaa-filled-value', place.formatted_address);
6572
}
6673

@@ -94,6 +101,7 @@ public function add_init_script( $form ) {
94101
'formId' => $this->_args['form_id'],
95102
'addressFieldId' => $this->_args['address_field_id'],
96103
'singleLineFieldId' => $this->_args['single_line_field_id'],
104+
'useFullAddress' => $this->_args['use_full_address'],
97105
);
98106

99107
$script = 'new GPAASingleLineInput( ' . json_encode( $args ) . ' );';
@@ -125,4 +133,5 @@ public function is_applicable_form( $form ) {
125133
'form_id' => 123, // The ID of your form.
126134
'address_field_id' => 4, // The ID of the Address field.
127135
'single_line_field_id' => 5, // The ID of the Single Line Text field.
136+
// 'use_full_address' => true, // Uncomment to use the full street address if you don't want an abbreviated street address.
128137
) );

0 commit comments

Comments
 (0)