gform_geolocation_place_autocomplete_element_options

Description

The gform_geolocation_place_autocomplete_element_options filter allows you to edit the constructor of the PlaceAutocompleteElement.

Usage

gform.addFilter('gform_geolocation_place_autocomplete_element_place_details', function(placeDetails, formId, fieldId, address) {
    // Your Custom Logic 
    return placeDetails;
});

Parameters

ParameterTypeDescription
placeDetailsobjectThe Field options.
formIdnumberThe ID of the form the address field belongs to.
fieldIdnumberThe ID of the address field autocomplete is to be initialized for.
addresselementThe Address field element.

More information about the API: https://developers.google.com/maps/documentation/javascript/reference/place#Place.fetchField

Examples

Limit the address selected options to only the United States.

gform.addFilter('gform_geolocation_place_autocomplete_element_options', function(options, formId, fieldId, address) {
	// Places API requires ISO 3166-1 Alpha-2 codes (like us, ca, gb, au, etc.).
	options.componentRestrictions = { country: ['us'] };

	return options;
});

Placement

Reference the article Adding JavaScript Code to the Frontend of Your Site.

Source Code

The filter is located in assets/js/src/theme/geolocation/google-place-address-element.js

Since

Geolocation 1.5.0