Search & Show by Place Name

Find addresses by their name. For example, “Mount Trashmore” in Virginia Beach would resolve to an address of “310 Edwin Drive, Virginia Beach, VA 23462”.

Instructions

  1. Install this snippet with our free Code Chest plugin.
    Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
    
    1. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.

Code

Filename: gpaa-show-place-name.js

/**
 * Gravity Perks // Address Autocomplete // Search & Show by Place Name
 * https://gravitywiz.com/documentation/gravity-forms-address-autocomplete/
 *
 * Find addresses by their name. For example, "Mount Trashmore" in Virginia Beach would resolve to
 * an address of "310 Edwin Drive, Virginia Beach, VA 23462".
 *
 * Instructions:
 *     1. Install this snippet with our free Code Chest plugin.
 *        Download the plugin here: https://gravitywiz.com/gravity-forms-code-chest/
 *     2. Copy and paste the snippet into the editor of the Custom Javascript for Gravity Forms plugin.
 */

// Enable search by Place Name
gform.addFilter( 'gpaa_autocomplete_options', function( options ) {
	options.types = [ 'geocode', 'establishment' ];
	options.fields.push( 'name' );
	return options;
} );

// Display Place Name
gform.addAction( 'gpaa_fields_filled', function ( place, instance, formId, fieldId ) {
	jQuery( '#input_{0}_{1}_1'.gformFormat( formId, fieldId ) ).val( place.name );
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.