Skip to content
Closed
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
15 changes: 11 additions & 4 deletions gp-address-autocomplete/gpaa-single-line-as-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 ) . ' );';
Expand Down Expand Up @@ -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.
) );