|
7 | 7 | * |
8 | 8 | * Use a Single Line Text field as autocomplete input and populate the Single Line Text field with the full address. |
9 | 9 | * |
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. |
11 | 11 | * |
12 | 12 | * Plugin Name: GP Address Autocomplete - Use Single Line Text field as Autocomplete Input |
13 | 13 | * Plugin URI: https://gravitywiz.com/documentation/gravity-forms-address-autocomplete/ |
@@ -60,7 +60,14 @@ public function output_script() { |
60 | 60 |
|
61 | 61 | gform.addFilter('gpaa_values', function (values, place, gpaa, formId, fieldId) { |
62 | 62 | 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 | + } |
64 | 71 | $input.data('gpaa-filled-value', place.formatted_address); |
65 | 72 | } |
66 | 73 |
|
@@ -94,6 +101,7 @@ public function add_init_script( $form ) { |
94 | 101 | 'formId' => $this->_args['form_id'], |
95 | 102 | 'addressFieldId' => $this->_args['address_field_id'], |
96 | 103 | 'singleLineFieldId' => $this->_args['single_line_field_id'], |
| 104 | + 'useFullAddress' => $this->_args['use_full_address'], |
97 | 105 | ); |
98 | 106 |
|
99 | 107 | $script = 'new GPAASingleLineInput( ' . json_encode( $args ) . ' );'; |
@@ -125,4 +133,5 @@ public function is_applicable_form( $form ) { |
125 | 133 | 'form_id' => 123, // The ID of your form. |
126 | 134 | 'address_field_id' => 4, // The ID of the Address field. |
127 | 135 | '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. |
128 | 137 | ) ); |
0 commit comments