From 2b8f3aea6d8515f81b8d31e19f564bb875cfb173 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Thu, 18 Jan 2024 08:27:30 +0530 Subject: [PATCH 1/4] `gpaa-single-line-as-input.php`: Added full address capability to the Single Line as Input functionality. --- .../gpaa-single-line-as-input.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gp-address-autocomplete/gpaa-single-line-as-input.php b/gp-address-autocomplete/gpaa-single-line-as-input.php index d7fb7f8cc..bd3443b0c 100644 --- a/gp-address-autocomplete/gpaa-single-line-as-input.php +++ b/gp-address-autocomplete/gpaa-single-line-as-input.php @@ -55,8 +55,13 @@ public function output_script() { window.GPAASingleLineInput = function( args ) { gform.addFilter('gpaa_values', function (values, place) { - values.autocomplete = place.formatted_address; - + if ( args.useFullAddress ) { + var fullAddress = instance.inputs.autocomplete.value; + values.autocomplete = fullAddress; + values.address1 = fullAddress.split(',')[0].trim(); + } else { + values.autocomplete = place.formatted_address; + } return values; }); } @@ -77,6 +82,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 ) . ' );'; @@ -107,5 +113,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, // Whether to use full street address or not ) ); From 2e82a1fcbe26787ee645988e7e8773ef08d9b702 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Fri, 19 Jan 2024 07:40:58 +0530 Subject: [PATCH 2/4] `gpaa-single-line-as-input.php`: Added full address capability to the Single Line as Input functionality. --- gp-address-autocomplete/gpaa-single-line-as-input.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gp-address-autocomplete/gpaa-single-line-as-input.php b/gp-address-autocomplete/gpaa-single-line-as-input.php index bd3443b0c..74e070540 100644 --- a/gp-address-autocomplete/gpaa-single-line-as-input.php +++ b/gp-address-autocomplete/gpaa-single-line-as-input.php @@ -56,6 +56,7 @@ public function output_script() { gform.addFilter('gpaa_values', function (values, place) { if ( args.useFullAddress ) { + // Logic borrowed from https://github.com/gravitywiz/snippet-library/pull/730 var fullAddress = instance.inputs.autocomplete.value; values.autocomplete = fullAddress; values.address1 = fullAddress.split(',')[0].trim(); @@ -114,5 +115,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, // Whether to use full street address or not + // 'use_full_address' => true, // Uncomment to use the full street address if you don't want an abbreviated street address. ) ); From 8f5832628990e676c2a5249660e74bbfb91a5e33 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Fri, 19 Jan 2024 07:43:15 +0530 Subject: [PATCH 3/4] `gpaa-single-line-as-input.php`: Added full address capability to the Single Line as Input functionality. --- gp-address-autocomplete/gpaa-single-line-as-input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gp-address-autocomplete/gpaa-single-line-as-input.php b/gp-address-autocomplete/gpaa-single-line-as-input.php index 74e070540..559a03516 100644 --- a/gp-address-autocomplete/gpaa-single-line-as-input.php +++ b/gp-address-autocomplete/gpaa-single-line-as-input.php @@ -115,5 +115,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. + // 'use_full_address' => true, // Uncomment to use the full street address if you don't want an abbreviated street address. ) ); From 0bdfe039e6c18b839a155585bcc75df96b0b2f4c Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Fri, 19 Jan 2024 15:57:57 +0530 Subject: [PATCH 4/4] `gpaa-single-line-as-input.php`: Added full address capability to the Single Line as Input functionality. --- gp-address-autocomplete/gpaa-single-line-as-input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gp-address-autocomplete/gpaa-single-line-as-input.php b/gp-address-autocomplete/gpaa-single-line-as-input.php index 559a03516..b16af9bb2 100644 --- a/gp-address-autocomplete/gpaa-single-line-as-input.php +++ b/gp-address-autocomplete/gpaa-single-line-as-input.php @@ -54,7 +54,7 @@ public function output_script() { ( function( $ ) { window.GPAASingleLineInput = function( args ) { - gform.addFilter('gpaa_values', function (values, place) { + gform.addFilter('gpaa_values', function (values, place, instance) { if ( args.useFullAddress ) { // Logic borrowed from https://github.com/gravitywiz/snippet-library/pull/730 var fullAddress = instance.inputs.autocomplete.value;