Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions gp-address-autocomplete/gpaa-single-line-as-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Use a Single Line Text field as autocomplete input and populate the Single Line Text field with the full address.
*
* Note: This snippet will require the user to make a selection from the auto-suggested addresses.
* Note: This snippet will require the user to make a selection from the auto-suggested addresses.
*
* Plugin Name: GP Address Autocomplete - Use Single Line Text field as Autocomplete Input
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-address-autocomplete/
Expand Down Expand Up @@ -60,7 +60,14 @@ public function output_script() {

gform.addFilter('gpaa_values', function (values, place, gpaa, formId, fieldId) {
if ( args.formId == formId && args.addressFieldId == fieldId ) {
values.autocomplete = place.formatted_address;
if ( args.useFullAddress ) {
// Logic borrowed from https://github.com/gravitywiz/snippet-library/pull/730
var fullAddress = gpaa.inputs.autocomplete.value;
values.autocomplete = fullAddress;
values.address1 = fullAddress.split(',')[0].trim();
} else {
values.autocomplete = place.formatted_address;
}
$input.data('gpaa-filled-value', place.formatted_address);
}

Expand Down Expand Up @@ -94,6 +101,7 @@ public function add_init_script( $form ) {
'formId' => $this->_args['form_id'],
'addressFieldId' => $this->_args['address_field_id'],
'singleLineFieldId' => $this->_args['single_line_field_id'],
'useFullAddress' => $this->_args['use_full_address'],
);

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