diff --git a/gp-address-autocomplete/gpaa-single-line-as-input.php b/gp-address-autocomplete/gpaa-single-line-as-input.php index e73450acf..16311c0ce 100644 --- a/gp-address-autocomplete/gpaa-single-line-as-input.php +++ b/gp-address-autocomplete/gpaa-single-line-as-input.php @@ -56,11 +56,16 @@ public function output_script() { ( function( $ ) { window.GPAASingleLineInput = function( args ) { - let $input = $('#input_' + args.formId + '_' + args.singleLineFieldId ); - 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); } @@ -94,6 +99,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 ) . ' );'; @@ -124,5 +130,6 @@ public function is_applicable_form( $form ) { new GPAA_Single_Line_Input( array( '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. + '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. ) );